use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class WorkflowTable method getRecord.
@Nullable
WorkflowRunRecord getRecord(WorkflowId id, String pid) throws IOException {
RunId runId = RunIds.fromString(pid);
long startTime = RunIds.getTime(runId, TimeUnit.SECONDS);
List<Field<?>> fields = getPrimaryKeyFields(id, startTime);
Optional<StructuredRow> indexRow = table.read(fields);
if (!indexRow.isPresent()) {
return null;
}
return getRunRecordFromRow(indexRow.get());
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class AppMetadataStore method queryProgramRuns.
/**
* Iterate over a range of run records, filter by predicates and pass each run record to the consumer.
* @param range to scan runRecordsTable with
* @param keyPredicate to filter the row keys by. If null, then does not filter.
* @param predicate to filter the runRecordMetas by. If null, then does not filter.
* @param limit the maximum number of entries to return
*/
private CloseableIterator<RunRecordDetail> queryProgramRuns(Range range, @Nullable Predicate<StructuredRow> keyPredicate, @Nullable Predicate<RunRecordDetail> predicate, int limit) throws IOException {
CloseableIterator<StructuredRow> iterator = getRunRecordsTable().scan(range, predicate == null && keyPredicate == null ? limit : Integer.MAX_VALUE);
return new AbstractCloseableIterator<RunRecordDetail>() {
private int currentLimit = limit;
@Override
protected RunRecordDetail computeNext() {
if (currentLimit <= 0) {
return endOfData();
}
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
if (keyPredicate != null && !keyPredicate.test(row)) {
continue;
}
RunRecordDetail recordMeta = deserializeRunRecordMeta(row);
if (predicate == null || predicate.test(recordMeta)) {
currentLimit--;
return recordMeta;
}
}
return endOfData();
}
@Override
public void close() {
iterator.close();
}
};
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class AppMetadataStore method getProgramRunCounts.
/**
* Get the run counts of the given program collections.
*
* @param programIds the collection of program ids to get the program
* @return the map of the program id to its run count
*/
public Map<ProgramId, Long> getProgramRunCounts(Collection<ProgramId> programIds) throws BadRequestException, IOException {
if (programIds.size() > 100) {
throw new BadRequestException(String.format("%d programs found, the maximum number supported is 100", programIds.size()));
}
Map<ProgramId, Long> result = programIds.stream().collect(Collectors.toMap(id -> id, id -> 0L, (v1, v2) -> 0L, LinkedHashMap::new));
List<List<Field<?>>> multiKeys = programIds.stream().map(id -> getProgramCountPrimaryKeys(TYPE_COUNT, id)).collect(Collectors.toList());
for (StructuredRow row : getProgramCountsTable().multiRead(multiKeys)) {
ProgramId programId = getApplicationIdFromRow(row).program(ProgramType.valueOf(row.getString(StoreDefinition.AppMetadataStore.PROGRAM_TYPE_FIELD)), row.getString(StoreDefinition.AppMetadataStore.PROGRAM_FIELD));
result.put(programId, row.getLong(StoreDefinition.AppMetadataStore.COUNTS));
}
return result;
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class ConfigTable method list.
public List<Config> list(String namespace, String type) throws IOException {
List<Field<?>> scanStart = new ArrayList<>(2);
scanStart.add(Fields.stringField(StoreDefinition.ConfigStore.NAMESPACE_FIELD, namespace));
scanStart.add(Fields.stringField(StoreDefinition.ConfigStore.TYPE_FIELD, type));
Range range = Range.singleton(scanStart);
try (CloseableIterator<StructuredRow> iter = table.scan(range, Integer.MAX_VALUE)) {
List<Config> result = new ArrayList<>();
while (iter.hasNext()) {
StructuredRow row = iter.next();
result.add(fromRow(row));
}
return result;
}
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class CapabilityStatusStore method getConfigs.
@Override
public Map<String, CapabilityConfig> getConfigs(Collection<String> capabilities) throws IOException {
List<List<Field<?>>> multiKeys = new ArrayList<>();
capabilities.forEach(capability -> multiKeys.add(Collections.singletonList(Fields.stringField(StoreDefinition.CapabilitiesStore.NAME_FIELD, capability))));
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable capabilityTable = context.getTable(StoreDefinition.CapabilitiesStore.CAPABILITIES);
return capabilityTable.multiRead(multiKeys).stream().collect(Collectors.toMap(structuredRow -> structuredRow.getString(StoreDefinition.CapabilitiesStore.NAME_FIELD), structuredRow -> GSON.fromJson(structuredRow.getString(StoreDefinition.CapabilitiesStore.CONFIG_FIELD), CapabilityConfig.class)));
}, IOException.class);
}
Aggregations