use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class ProgramScheduleStoreDataset method listSchedulesRecordsWithPrefix.
/**
* List schedule records with the given key prefix and only returns the schedules that can pass the filter.
*
* @param prefixKeys the prefix of the schedule records to be listed
* @param filter a filter that only returns true if the schedule record will be returned in the result
* @return the schedule records with the given key prefix that can pass the filter
*/
private List<ProgramScheduleRecord> listSchedulesRecordsWithPrefix(Collection<Field<?>> prefixKeys, Predicate<ProgramSchedule> filter) throws IOException {
List<ProgramScheduleRecord> result = new ArrayList<>();
try (CloseableIterator<StructuredRow> iterator = scheduleStore.scan(Range.singleton(prefixKeys), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
String serializedSchedule = row.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE);
if (serializedSchedule != null) {
ProgramSchedule schedule = GSON.fromJson(serializedSchedule, ProgramSchedule.class);
if (schedule != null && filter.test(schedule)) {
result.add(new ProgramScheduleRecord(schedule, extractMetaFromRow(schedule.getScheduleId(), row)));
}
}
}
}
return result;
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class ProgramScheduleStoreDataset method deleteSchedules.
/**
* Removes one or more schedules from the store. Succeeds whether the schedules exist or not.
*
* @param scheduleIds the schedules to delete
* @throws NotFoundException if one of the schedules does not exist in the store
*/
public void deleteSchedules(Iterable<? extends ScheduleId> scheduleIds, @Nullable Long deleteTime) throws NotFoundException, IOException {
if (deleteTime == null) {
deleteTime = System.currentTimeMillis();
}
for (ScheduleId scheduleId : scheduleIds) {
StructuredRow existingRow = readExistingScheduleRow(scheduleId);
markScheduleAsDeleted(existingRow, deleteTime);
Collection<Field<?>> scheduleKeys = getScheduleKeys(scheduleId);
triggerStore.deleteAll(Range.singleton(scheduleKeys));
}
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class ProgramScheduleStoreDataset method getScheduleRecord.
/**
* Read all information about a schedule from the store.
*
* @param scheduleId the id of the schedule to read
* @return the schedule record from the store
* @throws NotFoundException if the schedule does not exist in the store
*/
public ProgramScheduleRecord getScheduleRecord(ScheduleId scheduleId) throws NotFoundException, IOException {
StructuredRow row = readExistingScheduleRow(scheduleId);
String serializedSchedule = row.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE);
if (serializedSchedule == null) {
throw new NotFoundException(scheduleId);
}
ProgramSchedule schedule = GSON.fromJson(serializedSchedule, ProgramSchedule.class);
ProgramScheduleMeta meta = extractMetaFromRow(scheduleId, row);
return new ProgramScheduleRecord(schedule, meta);
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class DefaultSecretStore method list.
@Override
public <T> Collection<T> list(String namespace, Decoder<T> decoder) throws IOException {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = context.getTable(StoreDefinition.SecretStore.SECRET_STORE_TABLE);
Collection<Field<?>> partialKey = Collections.singletonList(Fields.stringField(StoreDefinition.SecretStore.NAMESPACE_FIELD, namespace));
try (CloseableIterator<StructuredRow> iterator = table.scan(Range.singleton(partialKey), Integer.MAX_VALUE)) {
List<T> list = new ArrayList<>();
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
list.add(decoder.decode(row.getBytes(StoreDefinition.SecretStore.SECRET_DATA_FIELD)));
}
return Collections.unmodifiableList(list);
}
}, IOException.class);
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class DatasetTypeTable method getTypes.
public Collection<DatasetTypeMeta> getTypes(NamespaceId namespaceId) throws IOException {
List<DatasetTypeMeta> types = Lists.newArrayList();
try (CloseableIterator<StructuredRow> iterator = getTypeTable().scan(Range.singleton(getModulePrefix(namespaceId.getEntityName())), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
String typeName = row.getString(StoreDefinition.DatasetTypeStore.TYPE_NAME_FIELD);
DatasetModuleId moduleId = GSON.fromJson(row.getString(StoreDefinition.DatasetTypeStore.DATASET_METADATA_FIELD), DatasetModuleId.class);
types.add(getTypeMeta(namespaceId, typeName, moduleId));
}
}
return types;
}
Aggregations