public void writeLogEntry(LogEntry logEntry) throws Throwable { List<Mutation> slice = new ArrayList<Mutation>(); slice.add(getMutation(LogEntryColumns.KS.toString(), logEntry.getKeyspace())); slice.add(getMutation(LogEntryColumns.CF.toString(), logEntry.getColumnFamily())); slice.add(getMutation(LogEntryColumns.ROW.toString(), logEntry.getRowKey())); slice.add(getMutation(LogEntryColumns.STATUS.toString(), logEntry.getStatus().toString())); slice.add( getMutation(LogEntryColumns.TIMESTAMP.toString(), Long.toString(logEntry.getTimestamp()))); slice.add(getMutation(LogEntryColumns.HOST.toString(), logEntry.getHost())); if (logEntry.hasErrors()) { for (String errorKey : logEntry.getErrors().keySet()) { slice.add(getMutation(errorKey, logEntry.getErrors().get(errorKey))); } } if (ConfigurationStore.getStore().shouldWriteColumns()) { for (ColumnOperation operation : logEntry.getOperations()) { if (operation.isDelete()) { slice.add(getMutation(operation.getName(), OperationType.DELETE)); } else { slice.add(getMutation(operation.getName(), OperationType.UPDATE)); } } } Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>(); Map<String, List<Mutation>> cfMutations = new HashMap<String, List<Mutation>>(); cfMutations.put(COLUMN_FAMILY, slice); ByteBuffer rowKey = ByteBufferUtil.bytes(logEntry.getUuid()); mutationMap.put(rowKey, cfMutations); getConnection(KEYSPACE).batch_mutate(mutationMap, logEntry.getConsistencyLevel()); }
private static List<LogEntry> toLogEntry(List<KeySlice> rows) throws Exception, Throwable { List<LogEntry> logEntries = new ArrayList<LogEntry>(); if (rows == null || rows.size() == 0) { return logEntries; } for (KeySlice keySlice : rows) { if (keySlice.columns.size() > 0) { LogEntry logEntry = new LogEntry(); logEntry.setUuid(ByteBufferUtil.string(keySlice.key)); for (ColumnOrSuperColumn cc : keySlice.columns) { if (ConfigurationStore.getStore().shouldWriteColumns()) { ColumnOperation operation = new ColumnOperation(); operation.setName(cc.column.name); operation.setOperationType(cc.column.value); } else { switch (LogEntryColumns.valueOf(ByteBufferUtil.string(cc.column.name))) { case KS: logEntry.setKeyspace(ByteBufferUtil.string(cc.column.value)); break; case CF: logEntry.setColumnFamily(ByteBufferUtil.string(cc.column.value)); break; case ROW: logEntry.setRowKey(cc.column.value); break; case STATUS: logEntry.setStatus(LogEntryStatus.valueOf(ByteBufferUtil.string(cc.column.value))); break; case TIMESTAMP: logEntry.setTimestamp(Long.valueOf(ByteBufferUtil.string(cc.column.value))); break; case HOST: logEntry.setHost(ByteBufferUtil.string(cc.column.value)); break; } } } logEntries.add(logEntry); } } return logEntries; }