Search in sources :

Example 16 with StructuredTable

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);
}
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 17 with StructuredTable

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);
}
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 18 with StructuredTable

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

Example 19 with StructuredTable

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

Example 20 with StructuredTable

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

Aggregations

StructuredTable (io.cdap.cdap.spi.data.StructuredTable)118 StructuredRow (io.cdap.cdap.spi.data.StructuredRow)60 Field (io.cdap.cdap.spi.data.table.field.Field)44 ArrayList (java.util.ArrayList)34 IOException (java.io.IOException)22 Range (io.cdap.cdap.spi.data.table.field.Range)18 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)14 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)12 HashMap (java.util.HashMap)12 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)10 Map (java.util.Map)10 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)8 PluginNotExistsException (io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException)8 List (java.util.List)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 Gson (com.google.gson.Gson)6 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)6 PluginClass (io.cdap.cdap.api.plugin.PluginClass)6 ArtifactAlreadyExistsException (io.cdap.cdap.common.ArtifactAlreadyExistsException)6 Connection (io.cdap.cdap.etl.proto.connection.Connection)6