Search in sources :

Example 1 with Namespace

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;
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) LoggerFactory(org.slf4j.LoggerFactory) TypeToken(com.google.common.reflect.TypeToken) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) PluginNotExistsException(io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException) ArtifactVersionRange(io.cdap.cdap.api.artifact.ArtifactVersionRange) Artifact(io.cdap.cdap.common.id.Id.Artifact) Gson(com.google.gson.Gson) ArtifactSortOrder(io.cdap.cdap.proto.artifact.ArtifactSortOrder) Map(java.util.Map) Nullable(javax.annotation.Nullable) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) Logger(org.slf4j.Logger) JsonSyntaxException(com.google.gson.JsonSyntaxException) ApplicationUpdateContext(io.cdap.cdap.api.app.ApplicationUpdateContext) Config(io.cdap.cdap.api.Config) Set(java.util.Set) PluginClass(io.cdap.cdap.api.plugin.PluginClass) List(java.util.List) Predicate(com.google.common.base.Predicate) Type(java.lang.reflect.Type) ApplicationConfigUpdateAction(io.cdap.cdap.api.app.ApplicationConfigUpdateAction) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) CaseInsensitiveEnumTypeAdapterFactory(io.cdap.cdap.common.io.CaseInsensitiveEnumTypeAdapterFactory) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) Preconditions(com.google.common.base.Preconditions) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Collections(java.util.Collections) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) Namespace(io.cdap.cdap.common.id.Id.Namespace) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) ArrayList(java.util.ArrayList) PluginNotExistsException(io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PluginNotExistsException(io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) PluginClass(io.cdap.cdap.api.plugin.PluginClass) Map(java.util.Map)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Predicate (com.google.common.base.Predicate)1 TypeToken (com.google.common.reflect.TypeToken)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Config (io.cdap.cdap.api.Config)1 ApplicationConfigUpdateAction (io.cdap.cdap.api.app.ApplicationConfigUpdateAction)1 ApplicationUpdateContext (io.cdap.cdap.api.app.ApplicationUpdateContext)1 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)1 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)1 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)1 ArtifactVersionRange (io.cdap.cdap.api.artifact.ArtifactVersionRange)1 PluginClass (io.cdap.cdap.api.plugin.PluginClass)1 Artifact (io.cdap.cdap.common.id.Id.Artifact)1 Namespace (io.cdap.cdap.common.id.Id.Namespace)1 CaseInsensitiveEnumTypeAdapterFactory (io.cdap.cdap.common.io.CaseInsensitiveEnumTypeAdapterFactory)1 ArtifactDescriptor (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor)1 ArtifactRepository (io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository)1 PluginNotExistsException (io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException)1