use of io.cdap.cdap.spi.data.StructuredTable 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.StructuredTable 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.StructuredTable 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);
}
use of io.cdap.cdap.spi.data.StructuredTable in project cdap by caskdata.
the class DefaultSecretStore method store.
@Override
public <T> void store(String namespace, String name, Encoder<T> encoder, T data) throws IOException {
TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = context.getTable(StoreDefinition.SecretStore.SECRET_STORE_TABLE);
List<Field<?>> fields = ImmutableList.<Field<?>>builder().addAll(getKeyFields(namespace, name)).add(Fields.bytesField(StoreDefinition.SecretStore.SECRET_DATA_FIELD, encoder.encode(data))).build();
table.upsert(fields);
}, IOException.class);
}
use of io.cdap.cdap.spi.data.StructuredTable in project cdap by caskdata.
the class ConnectionStore method listConnections.
/**
* Get all the connections in the given namespace
*
* @param namespace the namespace to look up
* @return the list of connections in this namespace
*/
public List<Connection> listConnections(NamespaceSummary namespace) {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = context.getTable(TABLE_ID);
Range range = Range.singleton(getNamespaceKeys(namespace));
List<Connection> connections = new ArrayList<>();
try (CloseableIterator<StructuredRow> rowIter = table.scan(range, Integer.MAX_VALUE)) {
rowIter.forEachRemaining(structuredRow -> connections.add(GSON.fromJson(structuredRow.getString(CONNECTION_DATA_FIELD), Connection.class)));
}
return connections;
});
}
Aggregations