@Override public List<WorkflowInstanceExecutionData> executionData(WorkflowId workflowId, String start, String stop) throws IOException { return bigtableStorage.executionData(workflowId, start, stop); }
@Override public Optional<Long> getLatestStoredCounter(WorkflowInstance workflowInstance) throws IOException { return bigtableStorage.getLatestStoredCounter(workflowInstance); }
@Override public SortedSet<SequenceEvent> readEvents(WorkflowInstance workflowInstance) throws IOException { return bigtableStorage.readEvents(workflowInstance); }
SortedSet<SequenceEvent> readEvents(WorkflowInstance workflowInstance) throws IOException { try (final Table eventsTable = connection.getTable(EVENTS_TABLE_NAME)) { final Scan scan = new Scan() .setRowPrefixFilter(Bytes.toBytes(workflowInstance.toKey() + '#')); final SortedSet<SequenceEvent> set = newSortedEventSet(); for (Result result : eventsTable.getScanner(scan)) { set.add(parseEventResult(result)); } return set; } }
@Override public void writeEvent(SequenceEvent sequenceEvent) throws IOException { bigtableStorage.writeEvent(sequenceEvent); }
public AggregateStorage(Connection connection, Datastore datastore, Duration retryBaseDelay) { this(new BigtableStorage(connection, retryBaseDelay), new DatastoreStorage(new CheckedDatastore(datastore), retryBaseDelay)); }
void writeEvent(SequenceEvent sequenceEvent) throws IOException { storeWithRetries(() -> { try (final Table eventsTable = connection.getTable(EVENTS_TABLE_NAME)) { final String workflowInstanceKey = sequenceEvent.event().workflowInstance().toKey(); final String keyString = String.format("%s#%08d", workflowInstanceKey, sequenceEvent.counter()); final byte[] key = Bytes.toBytes(keyString); final Put put = new Put(key, sequenceEvent.timestamp()); final byte[] eventBytes = serialize(sequenceEvent.event()).toByteArray(); put.addColumn(EVENT_CF, EVENT_QUALIFIER, eventBytes); eventsTable.put(put); } }); }
@Override public List<WorkflowInstanceExecutionData> executionData(WorkflowId workflowId, String offset, int limit) throws IOException { return bigtableStorage.executionData(workflowId, offset, limit); }
Optional<Long> getLatestStoredCounter(WorkflowInstance workflowInstance) throws IOException { final Set<SequenceEvent> storedEvents = readEvents(workflowInstance); final Optional<SequenceEvent> lastStoredEvent = storedEvents.stream().reduce((a, b) -> b); if (lastStoredEvent.isPresent()) { return Optional.of(lastStoredEvent.get().counter()); } else { return Optional.empty(); } }
@Override public WorkflowInstanceExecutionData executionData(WorkflowInstance workflowInstance) throws IOException { return bigtableStorage.executionData(workflowInstance); }
WorkflowInstanceExecutionData executionData(WorkflowInstance workflowInstance) throws IOException { SortedSet<SequenceEvent> events = readEvents(workflowInstance); if (events.isEmpty()) { throw new ResourceNotFoundException("Workflow instance not found"); } return WorkflowInstanceExecutionData.fromEvents(events); }
private List<WorkflowInstanceExecutionData> executionData( Set<WorkflowInstance> workflowInstancesSet) { return workflowInstancesSet.parallelStream() .map(workflowInstance -> { try { return executionData(workflowInstance); } catch (IOException e) { throw Throwables.propagate(e); } }) .sorted(WorkflowInstanceExecutionData.COMPARATOR) .collect(Collectors.toList()); }
List<WorkflowInstanceExecutionData> executionData(WorkflowId workflowId, String offset, int limit) throws IOException { try (final Table eventsTable = connection.getTable(EVENTS_TABLE_NAME)) { final Scan scan = new Scan() .setRowPrefixFilter(Bytes.toBytes(workflowId.toKey() + '#')) .setFilter(new FirstKeyOnlyFilter()); if (!Strings.isNullOrEmpty(offset)) { final WorkflowInstance offsetInstance = WorkflowInstance.create(workflowId, offset); scan.setStartRow(Bytes.toBytes(offsetInstance.toKey() + '#')); } final Set<WorkflowInstance> workflowInstancesSet = Sets.newHashSet(); try (ResultScanner scanner = eventsTable.getScanner(scan)) { Result result = scanner.next(); while (result != null) { final String key = new String(result.getRow()); final int lastHash = key.lastIndexOf('#'); final WorkflowInstance wfi = WorkflowInstance.parseKey(key.substring(0, lastHash)); workflowInstancesSet.add(wfi); if (workflowInstancesSet.size() == limit) { break; } result = scanner.next(); } } return executionData(workflowInstancesSet); } }
List<WorkflowInstanceExecutionData> executionData(WorkflowId workflowId, String start, String stop) throws IOException { try (final Table eventsTable = connection.getTable(EVENTS_TABLE_NAME)) { final Scan scan = new Scan() .setRowPrefixFilter(Bytes.toBytes(workflowId.toKey() + '#')) .setFilter(new FirstKeyOnlyFilter()); final WorkflowInstance startRow = WorkflowInstance.create(workflowId, start); scan.setStartRow(Bytes.toBytes(startRow.toKey() + '#')); if (!Strings.isNullOrEmpty(stop)) { final WorkflowInstance stopRow = WorkflowInstance.create(workflowId, stop); scan.setStopRow(Bytes.toBytes(stopRow.toKey() + '#')); } final Set<WorkflowInstance> workflowInstancesSet = Sets.newHashSet(); try (ResultScanner scanner = eventsTable.getScanner(scan)) { Result result = scanner.next(); while (result != null) { final String key = new String(result.getRow()); final int lastHash = key.lastIndexOf('#'); final WorkflowInstance wfi = WorkflowInstance.parseKey(key.substring(0, lastHash)); workflowInstancesSet.add(wfi); result = scanner.next(); } } return executionData(workflowInstancesSet); } }