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;
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations