use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class UsageTable method getDatasetsFromPrefix.
private Set<DatasetId> getDatasetsFromPrefix(List<Field<?>> prefix) throws IOException {
Set<DatasetId> datasets = new HashSet<>();
try (CloseableIterator<StructuredRow> iterator = table.scan(Range.singleton(prefix), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
datasets.add(GSON.fromJson(row.getString(StoreDefinition.UsageStore.DATASET_FIELD), DatasetKey.class).getDataset());
}
}
return datasets;
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class ArtifactStore method getApplicationClasses.
/**
* Get all application classes that belong to the specified namespace.
* Results are returned as a sorted map from artifact to application classes in that artifact.
* Map entries are sorted by the artifact.
*
* @param namespace the namespace from which to get application classes
* @return an unmodifiable map of artifact to a list of all application classes in that artifact.
* The map will never be null. If there are no application classes, an empty map will be returned.
*/
public SortedMap<ArtifactDescriptor, List<ApplicationClass>> getApplicationClasses(NamespaceId namespace) {
return TransactionRunners.run(transactionRunner, context -> {
SortedMap<ArtifactDescriptor, List<ApplicationClass>> result = Maps.newTreeMap();
StructuredTable table = getTable(context, StoreDefinition.ArtifactStore.APP_DATA_TABLE);
Collection<Field<?>> keys = Collections.singleton(Fields.stringField(StoreDefinition.ArtifactStore.NAMESPACE_FIELD, namespace.getNamespace()));
try (CloseableIterator<StructuredRow> iterator = table.scan(Range.singleton(keys), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
Map.Entry<ArtifactDescriptor, ApplicationClass> entry = extractApplicationClass(row);
List<ApplicationClass> existingAppClasses = result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>());
existingAppClasses.add(entry.getValue());
}
}
return Collections.unmodifiableSortedMap(result);
});
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class ArtifactStore method addPluginsInRangeToMap.
private void addPluginsInRangeToMap(final NamespaceId namespace, List<Id.Artifact> parentArtifacts, Iterator<StructuredRow> iterator, SortedMap<ArtifactDescriptor, PluginClass> plugins, @Nullable Predicate<io.cdap.cdap.proto.id.ArtifactId> range, int limit) {
// if predicate is null,
// filter out plugins whose artifacts are not in the system namespace and not in this namespace
range = range != null ? range : input -> NamespaceId.SYSTEM.equals(input.getParent()) || input.getParent().equals(namespace);
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
ImmutablePair<ArtifactDescriptor, PluginData> pluginPair = getPlugin(row, range);
if (pluginPair == null) {
continue;
}
PluginData pluginData = pluginPair.getSecond();
// filter out plugins that don't extend this version of the parent artifact
for (Id.Artifact parentArtifactId : parentArtifacts) {
if (pluginData.isUsableBy(parentArtifactId.toEntityId()) && isAllowed(pluginData.pluginClass)) {
plugins.put(pluginPair.getFirst(), pluginData.pluginClass);
break;
}
}
if (limit < plugins.size()) {
plugins.remove(plugins.lastKey());
}
}
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class ArtifactStore method getApplicationClasses.
/**
* Get all application classes that belong to the specified namespace of the specified classname.
* Results are returned as a sorted map from artifact to application classes in that artifact.
* Map entries are sorted by the artifact.
*
* @param namespace the namespace from which to get application classes
* @param className the classname of application classes to get
* @return an unmodifiable map of artifact the application classes in that artifact.
* The map will never be null. If there are no application classes, an empty map will be returned.
*/
public SortedMap<ArtifactDescriptor, ApplicationClass> getApplicationClasses(final NamespaceId namespace, final String className) {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = getTable(context, StoreDefinition.ArtifactStore.APP_DATA_TABLE);
SortedMap<ArtifactDescriptor, ApplicationClass> result = Maps.newTreeMap();
Collection<Field<?>> keys = ImmutableList.of(Fields.stringField(StoreDefinition.ArtifactStore.NAMESPACE_FIELD, namespace.getNamespace()), Fields.stringField(StoreDefinition.ArtifactStore.CLASS_NAME_FIELD, className));
try (CloseableIterator<StructuredRow> iterator = table.scan(Range.singleton(keys), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
Map.Entry<ArtifactDescriptor, ApplicationClass> entry = extractApplicationClass(row);
result.put(entry.getKey(), entry.getValue());
}
}
return Collections.unmodifiableSortedMap(result);
});
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
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);
}
Aggregations