com.datastax.driver.core.exceptions.QueryExecutionException Java Examples
The following examples show how to use
com.datastax.driver.core.exceptions.QueryExecutionException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraCqlIncrementalState.java From storm-cassandra-cql with Apache License 2.0 | 6 votes |
@Override public void commit(Long txid) { DriverException lastException = null; // Read current value. //if we failed to apply the update , maybe the state has change already , we need to calculate the new state and apply it again for (Map.Entry<K, V> entry : aggregateValues.entrySet()) { int attempts = 0; boolean applied = false; while (!applied && attempts < maxAttempts) { try{ applied = updateState(entry, txid); } catch(QueryExecutionException e) { lastException = e; LOG.warn("Catching {} attempt {}"+txid+"-"+partitionIndex, e.getMessage(), attempts); } attempts++; } if(!applied) { if(lastException != null) { throw new CassandraCqlIncrementalStateException("Ran out of attempts ["+attempts+"] max of ["+maxAttempts+"] "+txid+"-"+ partitionIndex, lastException); } else { throw new CassandraCqlIncrementalStateException("Ran out of attempts ["+attempts+"] max of ["+maxAttempts+"] "+txid+"-"+ partitionIndex); } } } }
Example #2
Source File: ChangeSetExecutionCommand.java From arcusplatform with Apache License 2.0 | 5 votes |
private void updateState(ExecutionContext context, Status status) throws CommandExecutionException { try { changeSet.setStatus(status); changeSet.setTimestamp(new Date()); context.getChangeSetDAO().update(changeSet); } catch(QueryExecutionException qee) { throw new CommandExecutionException(qee); } }
Example #3
Source File: ChangeLogExecutionCommand.java From arcusplatform with Apache License 2.0 | 5 votes |
private void insertHistory(ExecutionContext context, Status status) throws CommandExecutionException { try { VersionHistory history = new VersionHistory(); history.setStatus(status); history.setTimestamp(new Date()); history.setUsername(context.getManagerContext().getProfile().getUsername()); history.setVersion(changeLog.getVersion()); context.getVersionHistoryDAO().insert(history); } catch(QueryExecutionException qee) { throw new CommandExecutionException(qee); } }
Example #4
Source File: CQLExecutionCommand.java From arcusplatform with Apache License 2.0 | 5 votes |
private void executeCommand(Session session, Operation operation) throws CommandExecutionException { try { if(operation == Operation.UPGRADE) { session.execute(command.getUpdateCql()); } else { session.execute(command.getRollbackCql()); } } catch(QueryExecutionException | QueryValidationException e) { throw new CommandExecutionException(e); } }
Example #5
Source File: QueryCommand.java From FlareBot with MIT License | 5 votes |
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) { try { CassandraController.runUnsafeTask(conn -> { ResultSet set = conn.execute(MessageUtils.getMessage(args, 0)); List<String> header = new ArrayList<>(); List<List<String>> table = new ArrayList<>(); int columnsCount = set.getColumnDefinitions().size(); for (int i = 0; i < columnsCount; i++) { header.add(set.getColumnDefinitions().getName(i)); } for (Row setRow : set) { List<String> row = new ArrayList<>(); for (int i = 0; i < columnsCount; i++) { String value = setRow.getObject(i).toString(); row.add(value.substring(0, Math.min(30, value.length()))); } table.add(row); } String output = MessageUtils.makeAsciiTable(header, table, null); if (output.length() < 2000) { channel.sendMessage(output).queue(); } else { MessageUtils.sendErrorMessage("The query result set was very large, it has been posted to paste [here](" + MessageUtils .paste(output) + ")", channel, sender); } }); } catch (QueryExecutionException | QueryValidationException e) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Failed to execute query"); eb.addField("Error", "```\n" + e.getMessage() + "\n```", false); channel.sendMessage(eb.build()).queue(); } }
Example #6
Source File: CassandraController.java From FlareBot with MIT License | 5 votes |
public static void runTask(CassandraTask task) { try { task.execute(session); } catch (QueryExecutionException | QueryValidationException e) { FlareBot.LOGGER.error("Failed to execute Cassandra query", e); } }
Example #7
Source File: CassandraController.java From FlareBot with MIT License | 5 votes |
public static ResultSet execute(String query) { try { return session.execute(query); } catch (QueryExecutionException | QueryValidationException e) { FlareBot.LOGGER.error("Failed to execute Cassandra query", e); return null; } }
Example #8
Source File: CassandraOperationImpl.java From sunbird-lms-service with MIT License | 5 votes |
@Override public Response batchInsert( String keyspaceName, String tableName, List<Map<String, Object>> records) { long startTime = System.currentTimeMillis(); ProjectLogger.log( "Cassandra Service batchInsert method started at ==" + startTime, LoggerEnum.INFO); Session session = connectionManager.getSession(keyspaceName); Response response = new Response(); BatchStatement batchStatement = new BatchStatement(); ResultSet resultSet = null; try { for (Map<String, Object> map : records) { Insert insert = QueryBuilder.insertInto(keyspaceName, tableName); map.entrySet() .stream() .forEach( x -> { insert.value(x.getKey(), x.getValue()); }); batchStatement.add(insert); } resultSet = session.execute(batchStatement); response.put(Constants.RESPONSE, Constants.SUCCESS); } catch (QueryExecutionException | QueryValidationException | NoHostAvailableException | IllegalStateException e) { ProjectLogger.log("Cassandra Batch Insert Failed." + e.getMessage(), e); throw new ProjectCommonException( ResponseCode.SERVER_ERROR.getErrorCode(), ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode()); } logQueryElapseTime("batchInsert", startTime); return response; }
Example #9
Source File: CassandraOperationImpl.java From sunbird-lms-service with MIT License | 5 votes |
/** * This method updates all the records in a batch * * @param keyspaceName * @param tableName * @param records * @return */ // @Override public Response batchUpdateById( String keyspaceName, String tableName, List<Map<String, Object>> records) { long startTime = System.currentTimeMillis(); ProjectLogger.log( "Cassandra Service batchUpdateById method started at ==" + startTime, LoggerEnum.INFO); Session session = connectionManager.getSession(keyspaceName); Response response = new Response(); BatchStatement batchStatement = new BatchStatement(); ResultSet resultSet = null; try { for (Map<String, Object> map : records) { Update update = createUpdateStatement(keyspaceName, tableName, map); batchStatement.add(update); } resultSet = session.execute(batchStatement); response.put(Constants.RESPONSE, Constants.SUCCESS); } catch (QueryExecutionException | QueryValidationException | NoHostAvailableException | IllegalStateException e) { ProjectLogger.log("Cassandra Batch Update Failed." + e.getMessage(), e); throw new ProjectCommonException( ResponseCode.SERVER_ERROR.getErrorCode(), ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode()); } logQueryElapseTime("batchUpdateById", startTime); return response; }
Example #10
Source File: CassandraCqlMapState.java From storm-cassandra-cql with Apache License 2.0 | 5 votes |
protected void checkCassandraException(Exception e) { _mexceptions.incr(); if (e instanceof AlreadyExistsException || e instanceof AuthenticationException || e instanceof DriverException || e instanceof DriverInternalError || e instanceof InvalidConfigurationInQueryException || e instanceof InvalidQueryException || e instanceof InvalidTypeException || e instanceof QueryExecutionException || e instanceof QueryValidationException || e instanceof ReadTimeoutException || e instanceof SyntaxError || e instanceof TraceRetrievalException || e instanceof TruncateException || e instanceof UnauthorizedException || e instanceof UnavailableException || e instanceof ReadTimeoutException || e instanceof WriteTimeoutException || e instanceof ReadFailureException || e instanceof WriteFailureException || e instanceof FunctionExecutionException) { throw new ReportedFailedException(e); } else { throw new RuntimeException(e); } }
Example #11
Source File: CQLExecutor.java From Rhombus with MIT License | 5 votes |
public ResultSet executeSync(Statement cql) { if(logCql) { logger.debug("Executing QueryBuilder Query: {}", cql.toString()); } //just run a normal execute without a prepared statement try { return session.execute(cql); } catch(NoHostAvailableException e) { throw new RhombusTimeoutException(e); } catch(QueryExecutionException e2) { throw new RhombusTimeoutException(e2); } }
Example #12
Source File: CQLExecutor.java From Rhombus with MIT License | 5 votes |
public void executeBatch(List<CQLStatementIterator> statementIterators) { BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED); for(CQLStatementIterator statementIterator : statementIterators) { while(statementIterator.hasNext()) { CQLStatement statement = statementIterator.next(); batchStatement.add(getBoundStatement(session, statement)); } } try { session.execute(batchStatement); } catch(NoHostAvailableException e) { throw new RhombusTimeoutException(e); } catch(QueryExecutionException e2) { throw new RhombusTimeoutException(e2); } }
Example #13
Source File: CassandraController.java From FlareBot with MIT License | 4 votes |
public static void runUnsafeTask(CassandraTask task) throws QueryExecutionException, QueryValidationException { task.execute(session); }
Example #14
Source File: CassandraOperationImpl.java From sunbird-lms-service with MIT License | 4 votes |
/** * This method performs batch operations of insert and update on a same table, further other * operations can be added to if it is necessary. * * @param keySpaceName * @param tableName * @param inputData * @return */ @Override public Response performBatchAction( String keySpaceName, String tableName, Map<String, Object> inputData) { long startTime = System.currentTimeMillis(); ProjectLogger.log( "Cassandra Service performBatchAction method started at ==" + startTime, LoggerEnum.INFO.name()); Session session = connectionManager.getSession(keySpaceName); Response response = new Response(); BatchStatement batchStatement = new BatchStatement(); ResultSet resultSet = null; try { inputData.forEach( (key, inputMap) -> { Map<String, Object> record = (Map<String, Object>) inputMap; if (key.equals(JsonKey.INSERT)) { Insert insert = createInsertStatement(keySpaceName, tableName, record); batchStatement.add(insert); } else if (key.equals(JsonKey.UPDATE)) { Update update = createUpdateStatement(keySpaceName, tableName, record); batchStatement.add(update); } }); resultSet = session.execute(batchStatement); response.put(Constants.RESPONSE, Constants.SUCCESS); } catch (QueryExecutionException | QueryValidationException | NoHostAvailableException | IllegalStateException e) { ProjectLogger.log( "Cassandra performBatchAction Failed." + e.getMessage(), LoggerEnum.ERROR.name()); throw new ProjectCommonException( ResponseCode.SERVER_ERROR.getErrorCode(), ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode()); } logQueryElapseTime("performBatchAction", startTime); return response; }
Example #15
Source File: CassandraOperationImpl.java From sunbird-lms-service with MIT License | 4 votes |
@Override public Response batchInsertWithTTL( String keyspaceName, String tableName, List<Map<String, Object>> records, List<Integer> ttls) { long startTime = System.currentTimeMillis(); ProjectLogger.log( "CassandraOperationImpl:batchInsertWithTTL: call started at " + startTime, LoggerEnum.INFO); if (CollectionUtils.isEmpty(records) || CollectionUtils.isEmpty(ttls)) { ProjectLogger.log( "CassandraOperationImpl:batchInsertWithTTL: records or ttls is empty", LoggerEnum.ERROR); ProjectCommonException.throwServerErrorException(ResponseCode.SERVER_ERROR); } if (ttls.size() != records.size()) { ProjectLogger.log( "CassandraOperationImpl:batchInsertWithTTL: Mismatch of records and ttls list size", LoggerEnum.ERROR); ProjectCommonException.throwServerErrorException(ResponseCode.SERVER_ERROR); } Session session = connectionManager.getSession(keyspaceName); Response response = new Response(); BatchStatement batchStatement = new BatchStatement(); ResultSet resultSet = null; Iterator<Integer> ttlIterator = ttls.iterator(); try { for (Map<String, Object> map : records) { Insert insert = QueryBuilder.insertInto(keyspaceName, tableName); map.entrySet() .stream() .forEach( x -> { insert.value(x.getKey(), x.getValue()); }); if (ttlIterator.hasNext()) { Integer ttlVal = ttlIterator.next(); if (ttlVal != null & ttlVal > 0) { insert.using(QueryBuilder.ttl(ttlVal)); } } batchStatement.add(insert); } resultSet = session.execute(batchStatement); response.put(Constants.RESPONSE, Constants.SUCCESS); } catch (QueryExecutionException | QueryValidationException | NoHostAvailableException | IllegalStateException e) { ProjectLogger.log( "CassandraOperationImpl:batchInsertWithTTL: Exception occurred with error message = " + e.getMessage(), e); throw new ProjectCommonException( ResponseCode.SERVER_ERROR.getErrorCode(), ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode()); } logQueryElapseTime("batchInsertWithTTL", startTime); return response; }