use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
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;
});
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class OAuthStore method getProvider.
/**
* Get an OAuth provider.
*
* @param name name of {@link OAuthProvider} to read
* @throws OAuthStoreException if the read fails
*/
public Optional<OAuthProvider> getProvider(String name) throws OAuthStoreException {
OAuthClientCredentials clientCreds;
try {
String clientCredsJson = new String(secureStore.get(NamespaceId.SYSTEM.getNamespace(), getClientCredsKey(name)).get(), StandardCharsets.UTF_8);
clientCreds = GSON.fromJson(clientCredsJson, OAuthClientCredentials.class);
} catch (IOException e) {
throw new OAuthStoreException("Failed to read from OAuth provider secure storage", e);
} catch (Exception e) {
return Optional.empty();
}
try {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = context.getTable(TABLE_ID);
Optional<StructuredRow> row = table.read(getKey(name));
return row.map(structuredRow -> fromRow(structuredRow, clientCreds));
}, TableNotFoundException.class, InvalidFieldException.class);
} catch (TableNotFoundException e) {
throw new OAuthStoreException("OAuth provider table not found", e);
} catch (InvalidFieldException e) {
throw new OAuthStoreException("OAuth provider object fields do not match table", e);
}
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class DraftStore method getDraft.
/**
* Fetch a given draft if it exists
*
* @param id {@link DraftId} that is used to uniquely identify a draft
* @return an {@link Optional<Draft>} representing the requested draft
* @throws TableNotFoundException if the draft store table is not found
* @throws InvalidFieldException if the fields in the {@link DraftId} object do not match the fields in the
* StructuredTable
*/
public Optional<Draft> getDraft(DraftId id) throws TableNotFoundException, InvalidFieldException {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = context.getTable(TABLE_ID);
Optional<StructuredRow> row = table.read(getKey(id));
return row.map(this::fromRow);
}, TableNotFoundException.class, InvalidFieldException.class);
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class ArtifactStore method getPluginClasses.
/**
* Get all plugin classes of the given type that extend the given parent artifact.
* Results are returned as a map from plugin artifact to plugins in that artifact.
*
* @param namespace the namespace to search for plugins. The system namespace is always included
* @param parentArtifactId the id of the artifact to find plugins for
* @param type the type of plugin to look for or {@code null} for matching any type
* @return an unmodifiable map of plugin artifact to plugin classes for all plugin classes accessible by the
* given artifact. The map will never be null. If there are no plugin classes, an empty map will be returned.
* @throws ArtifactNotFoundException if the artifact to find plugins for does not exist
* @throws IOException if there was an exception reading metadata from the metastore
*/
public SortedMap<ArtifactDescriptor, Set<PluginClass>> getPluginClasses(NamespaceId namespace, Id.Artifact parentArtifactId, @Nullable String type) throws ArtifactNotFoundException, IOException {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable artifactDataTable = getTable(context, StoreDefinition.ArtifactStore.ARTIFACT_DATA_TABLE);
SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = getPluginsInArtifact(artifactDataTable, parentArtifactId, input -> (type == null || type.equals(input.getType())) && isAllowed(input));
// Scan plugins
StructuredTable pluginTable = getTable(context, StoreDefinition.ArtifactStore.PLUGIN_DATA_TABLE);
try (CloseableIterator<StructuredRow> iterator = pluginTable.scan(createPluginScanRange(parentArtifactId, type), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
addPluginToMap(namespace, parentArtifactId, plugins, row);
}
}
// Scan universal plugins
StructuredTable uniPluginTable = getTable(context, StoreDefinition.ArtifactStore.UNIV_PLUGIN_DATA_TABLE);
List<Range> ranges = Arrays.asList(createUniversalPluginScanRange(namespace.getNamespace(), type), createUniversalPluginScanRange(NamespaceId.SYSTEM.getNamespace(), type));
for (Range range : ranges) {
try (CloseableIterator<StructuredRow> iterator = uniPluginTable.scan(range, Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
addPluginToMap(namespace, parentArtifactId, plugins, row);
}
}
}
return Collections.unmodifiableSortedMap(plugins);
}, ArtifactNotFoundException.class, IOException.class);
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class ArtifactStore method deleteRangeFromTable.
private void deleteRangeFromTable(StructuredTable table, Range range) throws IOException {
try (CloseableIterator<StructuredRow> iterator = table.scan(range, Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
table.delete(row.getPrimaryKeys());
}
}
}
Aggregations