Search in sources :

Example 56 with StructuredRow

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;
}
Also used : ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) ArrayList(java.util.ArrayList) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ProgramScheduleRecord(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleRecord)

Example 57 with StructuredRow

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));
    }
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Example 58 with StructuredRow

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);
}
Also used : ProgramScheduleMeta(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleMeta) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramScheduleRecord(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleRecord)

Example 59 with StructuredRow

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);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ArrayList(java.util.ArrayList)

Example 60 with StructuredRow

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;
}
Also used : DatasetModuleId(io.cdap.cdap.proto.id.DatasetModuleId) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) StructuredRow(io.cdap.cdap.spi.data.StructuredRow)

Aggregations

StructuredRow (io.cdap.cdap.spi.data.StructuredRow)142 StructuredTable (io.cdap.cdap.spi.data.StructuredTable)68 Field (io.cdap.cdap.spi.data.table.field.Field)66 ArrayList (java.util.ArrayList)54 Range (io.cdap.cdap.spi.data.table.field.Range)36 HashSet (java.util.HashSet)28 IOException (java.io.IOException)22 HashMap (java.util.HashMap)22 LinkedHashSet (java.util.LinkedHashSet)22 List (java.util.List)20 LinkedHashMap (java.util.LinkedHashMap)18 Map (java.util.Map)18 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)16 Collection (java.util.Collection)16 Set (java.util.Set)16 Nullable (javax.annotation.Nullable)16 ImmutableList (com.google.common.collect.ImmutableList)14 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)14 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)14 Fields (io.cdap.cdap.spi.data.table.field.Fields)14