use of io.cdap.cdap.common.id.Id.Namespace in project cdap by caskdata.
the class DefaultApplicationUpdateContext method getScopedPluginArtifacts.
private List<ArtifactId> getScopedPluginArtifacts(String pluginType, String pluginName, ArtifactScope pluginScope, @Nullable ArtifactVersionRange pluginRange, int limit) throws Exception {
List<ArtifactId> pluginArtifacts = new ArrayList<>();
NamespaceId pluginArtifactNamespace = ArtifactScope.SYSTEM.equals(pluginScope) ? NamespaceId.SYSTEM : namespaceId;
Predicate<io.cdap.cdap.proto.id.ArtifactId> predicate = input -> {
// Check if it is from the scoped namespace and should check if plugin is in given range if provided.
return (pluginArtifactNamespace.equals(input.getParent()) && (pluginRange == null || pluginRange.versionIsInRange(new ArtifactVersion(input.getVersion()))));
};
try {
// TODO: Pass ArtifactSortOrder as argument for better flexibility.
Map<ArtifactDescriptor, PluginClass> plugins = artifactRepository.getPlugins(pluginArtifactNamespace, Artifact.from(Namespace.fromEntityId(namespaceId), applicationArtifactId), pluginType, pluginName, predicate, limit, ArtifactSortOrder.ASC);
for (Map.Entry<ArtifactDescriptor, PluginClass> pluginsEntry : plugins.entrySet()) {
ArtifactId plugin = pluginsEntry.getKey().getArtifactId();
// Consider if it is a non-snapshot version artifact or it is a snapshot version than allowSnapshot is true.
if ((plugin.getVersion().isSnapshot() && allowSnapshot) || !plugin.getVersion().isSnapshot()) {
pluginArtifacts.add(plugin);
}
}
} catch (PluginNotExistsException e) {
LOG.trace("No plugin found for plugin {} of type {} in scope {} for app {}", pluginName, pluginType, pluginScope, applicationId, e);
return Collections.emptyList();
} catch (Exception e) {
throw e;
}
return pluginArtifacts;
}
Aggregations