Search in sources :

Example 21 with Field

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

Example 22 with Field

use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.

the class CapabilityStatusStore method addOrUpdateCapabilityOperation.

/**
 * Adds or update capability operations
 *
 * @param capability
 * @param actionType
 * @param config
 * @throws IOException
 */
public void addOrUpdateCapabilityOperation(String capability, CapabilityAction actionType, CapabilityConfig config) throws IOException {
    TransactionRunners.run(transactionRunner, context -> {
        StructuredTable capabilityTable = context.getTable(StoreDefinition.CapabilitiesStore.CAPABILITY_OPERATIONS);
        Collection<Field<?>> fields = new ArrayList<>();
        fields.add(Fields.stringField(StoreDefinition.CapabilitiesStore.NAME_FIELD, capability));
        fields.add(Fields.stringField(StoreDefinition.CapabilitiesStore.ACTION_FIELD, actionType.name().toLowerCase()));
        fields.add(Fields.stringField(StoreDefinition.CapabilitiesStore.CONFIG_FIELD, GSON.toJson(config)));
        capabilityTable.upsert(fields);
    }, IOException.class);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) ArrayList(java.util.ArrayList)

Example 23 with Field

use of io.cdap.cdap.spi.data.table.field.Field 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);
}
Also used : TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) StoreDefinition(io.cdap.cdap.store.StoreDefinition) Inject(com.google.inject.Inject) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) Collection(java.util.Collection) Fields(io.cdap.cdap.spi.data.table.field.Fields) IOException(java.io.IOException) HashMap(java.util.HashMap) CloseableIterator(io.cdap.cdap.api.dataset.lib.CloseableIterator) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Gson(com.google.gson.Gson) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) Range(io.cdap.cdap.spi.data.table.field.Range) Map(java.util.Map) Field(io.cdap.cdap.spi.data.table.field.Field) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Collections(java.util.Collections) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with Field

use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.

the class DefaultSecretStore method delete.

@Override
public void delete(String namespace, String name) throws SecretNotFoundException, IOException {
    TransactionRunners.run(transactionRunner, context -> {
        StructuredTable table = context.getTable(StoreDefinition.SecretStore.SECRET_STORE_TABLE);
        List<Field<?>> keyFields = ImmutableList.<Field<?>>builder().addAll(getKeyFields(namespace, name)).build();
        if (!table.read(keyFields).isPresent()) {
            throw new SecretNotFoundException(namespace, name);
        }
        table.delete(keyFields);
    }, SecretNotFoundException.class, IOException.class);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) SecretNotFoundException(io.cdap.cdap.securestore.spi.SecretNotFoundException)

Example 25 with Field

use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.

the class DefaultSecretStore method get.

@Override
public <T> T get(String namespace, String name, Decoder<T> decoder) throws SecretNotFoundException, IOException {
    return TransactionRunners.run(transactionRunner, context -> {
        StructuredTable table = context.getTable(StoreDefinition.SecretStore.SECRET_STORE_TABLE);
        List<Field<?>> keyFields = ImmutableList.<Field<?>>builder().addAll(getKeyFields(namespace, name)).build();
        Optional<StructuredRow> optionalRow = table.read(keyFields);
        if (!optionalRow.isPresent()) {
            throw new SecretNotFoundException(namespace, name);
        }
        StructuredRow row = optionalRow.get();
        return decoder.decode(row.getBytes(StoreDefinition.SecretStore.SECRET_DATA_FIELD));
    }, SecretNotFoundException.class, 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) SecretNotFoundException(io.cdap.cdap.securestore.spi.SecretNotFoundException)

Aggregations

Field (io.cdap.cdap.spi.data.table.field.Field)72 StructuredRow (io.cdap.cdap.spi.data.StructuredRow)40 StructuredTable (io.cdap.cdap.spi.data.StructuredTable)33 ArrayList (java.util.ArrayList)33 Range (io.cdap.cdap.spi.data.table.field.Range)24 HashSet (java.util.HashSet)18 Map (java.util.Map)17 List (java.util.List)16 Nullable (javax.annotation.Nullable)16 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)15 Collections (java.util.Collections)15 HashMap (java.util.HashMap)15 LinkedHashSet (java.util.LinkedHashSet)15 Set (java.util.Set)15 Fields (io.cdap.cdap.spi.data.table.field.Fields)14 Collection (java.util.Collection)14 LinkedHashMap (java.util.LinkedHashMap)14 Collectors (java.util.stream.Collectors)14 Optional (java.util.Optional)13 IOException (java.io.IOException)12