use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactStore method getPluginClasses.
/**
* Get all plugin classes of the given type and name 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 parentArtifactRange the parent artifact range to find plugins for
* @param type the type of plugin to look for
* @param name the name of the plugin to look for
* @param pluginRange the predicate for the plugins
* @param limit the limit number of the result
* @param order the order of the result
* @return an unmodifiable map of plugin artifact to plugin classes of the given type and name, accessible by the
* given artifact. The map will never be null, and will never be empty.
* @throws PluginNotExistsException if no plugin with the given type and name exists in the namespace
* @throws IOException if there was an exception reading metadata from the metastore
*/
public SortedMap<ArtifactDescriptor, PluginClass> getPluginClasses(NamespaceId namespace, ArtifactRange parentArtifactRange, String type, String name, @Nullable final Predicate<io.cdap.cdap.proto.id.ArtifactId> pluginRange, int limit, ArtifactSortOrder order) throws IOException, ArtifactNotFoundException, PluginNotExistsException {
SortedMap<ArtifactDescriptor, PluginClass> result = TransactionRunners.run(transactionRunner, context -> {
StructuredTable artifactDataTable = getTable(context, StoreDefinition.ArtifactStore.ARTIFACT_DATA_TABLE);
List<ArtifactDetail> parentArtifactDetails = getArtifacts(artifactDataTable, parentArtifactRange, Integer.MAX_VALUE, null);
if (parentArtifactDetails.isEmpty()) {
throw new ArtifactNotFoundException(parentArtifactRange.getNamespace(), parentArtifactRange.getName());
}
SortedMap<ArtifactDescriptor, PluginClass> plugins = order == ArtifactSortOrder.DESC ? new TreeMap<>(Collections.reverseOrder()) : new TreeMap<>();
List<Id.Artifact> parentArtifacts = new ArrayList<>();
for (ArtifactDetail parentArtifactDetail : parentArtifactDetails) {
parentArtifacts.add(Id.Artifact.from(Id.Namespace.from(parentArtifactRange.getNamespace()), parentArtifactDetail.getDescriptor().getArtifactId()));
Set<PluginClass> parentPlugins = parentArtifactDetail.getMeta().getClasses().getPlugins();
for (PluginClass pluginClass : parentPlugins) {
if (pluginClass.getName().equals(name) && pluginClass.getType().equals(type) && isAllowed(pluginClass)) {
plugins.put(parentArtifactDetail.getDescriptor(), pluginClass);
break;
}
}
}
// Add all plugins that extends from the given set of parents
StructuredTable pluginTable = getTable(context, StoreDefinition.ArtifactStore.PLUGIN_DATA_TABLE);
PluginKeyPrefix pluginKey = new PluginKeyPrefix(parentArtifactRange.getNamespace(), parentArtifactRange.getName(), type, name);
try (CloseableIterator<StructuredRow> iterator = pluginTable.scan(Range.singleton(pluginKey.keys), Integer.MAX_VALUE)) {
addPluginsInRangeToMap(namespace, parentArtifacts, iterator, plugins, pluginRange, limit);
}
// Add all universal plugins
StructuredTable uniPluginTable = getTable(context, StoreDefinition.ArtifactStore.UNIV_PLUGIN_DATA_TABLE);
for (String ns : Arrays.asList(namespace.getNamespace(), NamespaceId.SYSTEM.getNamespace())) {
UniversalPluginKeyPrefix universalPluginKey = new UniversalPluginKeyPrefix(ns, type, name);
try (CloseableIterator<StructuredRow> iterator = uniPluginTable.scan(Range.singleton(universalPluginKey.keys), Integer.MAX_VALUE)) {
addPluginsInRangeToMap(namespace, parentArtifacts, iterator, plugins, pluginRange, limit);
}
}
return Collections.unmodifiableSortedMap(plugins);
}, IOException.class, ArtifactNotFoundException.class);
if (result.isEmpty()) {
throw new PluginNotExistsException(new NamespaceId(parentArtifactRange.getNamespace()), type, name);
}
return result;
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AbstractContext method getDataset.
@Override
public <T extends Dataset> T getDataset(final String namespace, final String name, final Map<String, String> arguments, final AccessType accessType) throws DatasetInstantiationException {
return Retries.callWithRetries(() -> {
T dataset = datasetCache.getDataset(namespace, name, arguments, accessType);
if (dataset instanceof RuntimeProgramContextAware) {
DatasetId datasetId = new NamespaceId(namespace).dataset(name);
((RuntimeProgramContextAware) dataset).setContext(createRuntimeProgramContext(datasetId));
}
return dataset;
}, retryStrategy);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class Artifacts method toProtoArtifactId.
/**
* Converts a {@link ArtifactId} to {@link io.cdap.cdap.proto.id.ArtifactId}.
*
* @param namespaceId the user namespace to use
* @param artifactId the artifact id to convert
*/
public static io.cdap.cdap.proto.id.ArtifactId toProtoArtifactId(NamespaceId namespaceId, ArtifactId artifactId) {
ArtifactScope scope = artifactId.getScope();
NamespaceId artifactNamespace = scope == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : namespaceId;
return artifactNamespace.artifact(artifactId.getName(), artifactId.getVersion().getVersion());
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class LocalPreferencesFetcherInternal method get.
/**
* Get preferences for the given identify
*/
public PreferencesDetail get(EntityId entityId, boolean resolved) {
final PreferencesService service = preferencesService;
PreferencesDetail detail = null;
switch(entityId.getEntityType()) {
case INSTANCE:
detail = resolved ? service.getResolvedPreferences() : service.getPreferences();
break;
case NAMESPACE:
NamespaceId namespaceId = (NamespaceId) entityId;
detail = resolved ? service.getResolvedPreferences(namespaceId) : service.getPreferences(namespaceId);
break;
case APPLICATION:
ApplicationId appId = (ApplicationId) entityId;
detail = resolved ? service.getResolvedPreferences(appId) : service.getPreferences(appId);
break;
case PROGRAM:
ProgramId programId = (ProgramId) entityId;
detail = resolved ? service.getResolvedPreferences(programId) : service.getPreferences(programId);
break;
default:
throw new UnsupportedOperationException(String.format("Preferences cannot be used on this entity type: %s", entityId.getEntityType()));
}
return detail;
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class LocalApplicationDetailFetcher method list.
/**
* Get a list of {@link ApplicationDetail} for all applications in the given namespace
*
* @param namespace the name of the namespace to get the list of applications
* @return a list of {@link ApplicationDetail} for all applications in the given namespace
* @throws IOException if failed to get the list of {@link ApplicationDetail}
* @throws NamespaceNotFoundException if the given namespace doesn't exit
*/
@Override
public List<ApplicationDetail> list(String namespace) throws IOException, NamespaceNotFoundException {
NamespaceId namespaceId = new NamespaceId(namespace);
List<ApplicationDetail> detailList = Collections.emptyList();
try {
// the existence of the namespace. Does a check here to explicitly throw an exception if nonexistent.
if (!namespaceQueryAdmin.exists(namespaceId)) {
throw new NamespaceNotFoundException(namespaceId);
}
detailList = applicationLifecycleService.getApps(namespaceId);
} catch (Exception e) {
Throwables.propagateIfPossible(e, NamespaceNotFoundException.class, IOException.class);
throw new IOException(e);
}
return detailList;
}
Aggregations