Search in sources :

Example 1 with ArtifactSortOrder

use of co.cask.cdap.proto.artifact.ArtifactSortOrder in project cdap by caskdata.

the class ArtifactHttpHandler method getArtifactVersions.

@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}")
public void getArtifactVersions(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @QueryParam("scope") @DefaultValue("user") String scope, @QueryParam("artifactVersion") String versionRange, @QueryParam("limit") @DefaultValue("2147483647") String limit, @QueryParam("order") @DefaultValue("UNORDERED") String order) throws Exception {
    NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope);
    ArtifactRange range = versionRange == null ? null : new ArtifactRange(namespaceId, artifactName, ArtifactVersionRange.parse(versionRange));
    int limitNumber = Integer.valueOf(limit);
    limitNumber = limitNumber <= 0 ? Integer.MAX_VALUE : limitNumber;
    ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order);
    try {
        if (range == null) {
            responder.sendJson(HttpResponseStatus.OK, artifactRepository.getArtifactSummaries(namespace, artifactName, limitNumber, sortOrder));
        } else {
            responder.sendJson(HttpResponseStatus.OK, artifactRepository.getArtifactSummaries(range, limitNumber, sortOrder));
        }
    } catch (IOException e) {
        LOG.error("Exception reading artifacts named {} for namespace {} from the store.", artifactName, namespaceId, e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store.");
    }
}
Also used : ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) NamespaceId(co.cask.cdap.proto.id.NamespaceId) IOException(java.io.IOException) PluginEndpoint(co.cask.cdap.internal.app.runtime.plugin.PluginEndpoint) ArtifactSortOrder(co.cask.cdap.proto.artifact.ArtifactSortOrder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with ArtifactSortOrder

use of co.cask.cdap.proto.artifact.ArtifactSortOrder in project cdap by caskdata.

the class ArtifactHttpHandler method getArtifactPlugin.

@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/" + "versions/{artifact-version}/extensions/{plugin-type}/plugins/{plugin-name}")
public void getArtifactPlugin(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("plugin-type") String pluginType, @PathParam("plugin-name") String pluginName, @QueryParam("scope") @DefaultValue("user") final String scope, @QueryParam("artifactName") final String pluginArtifactName, @QueryParam("artifactVersion") String pluginVersion, @QueryParam("artifactScope") final String pluginScope, @QueryParam("limit") @DefaultValue("2147483647") String limit, @QueryParam("order") @DefaultValue("UNORDERED") String order) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException, InvalidArtifactRangeException {
    NamespaceId namespace = Ids.namespace(namespaceId);
    NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope);
    final NamespaceId pluginArtifactNamespace = validateAndGetScopedNamespace(namespace, pluginScope);
    Id.Artifact parentArtifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
    final ArtifactVersionRange pluginRange = pluginVersion == null ? null : ArtifactVersionRange.parse(pluginVersion);
    int limitNumber = Integer.valueOf(limit);
    limitNumber = limitNumber <= 0 ? Integer.MAX_VALUE : limitNumber;
    ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order);
    Predicate<ArtifactId> predicate = new Predicate<ArtifactId>() {

        @Override
        public boolean apply(ArtifactId input) {
            // by default, the scoped namespace is for USER scope
            return (((pluginScope == null && NamespaceId.SYSTEM.equals(input.getParent())) || pluginArtifactNamespace.equals(input.getParent())) && (pluginArtifactName == null || pluginArtifactName.equals(input.getArtifact())) && (pluginRange == null || pluginRange.versionIsInRange(new ArtifactVersion(input.getVersion()))));
        }
    };
    try {
        SortedMap<ArtifactDescriptor, PluginClass> plugins = artifactRepository.getPlugins(namespace, parentArtifactId, pluginType, pluginName, predicate, limitNumber, sortOrder);
        List<PluginInfo> pluginInfos = Lists.newArrayList();
        // flatten the map
        for (Map.Entry<ArtifactDescriptor, PluginClass> pluginsEntry : plugins.entrySet()) {
            ArtifactDescriptor pluginArtifact = pluginsEntry.getKey();
            ArtifactSummary pluginArtifactSummary = ArtifactSummary.from(pluginArtifact.getArtifactId());
            PluginClass pluginClass = pluginsEntry.getValue();
            pluginInfos.add(new PluginInfo(pluginClass.getName(), pluginClass.getType(), pluginClass.getDescription(), pluginClass.getClassName(), pluginArtifactSummary, pluginClass.getProperties(), pluginClass.getEndpoints()));
        }
        responder.sendJson(HttpResponseStatus.OK, pluginInfos);
    } catch (PluginNotExistsException e) {
        responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage());
    } catch (IOException e) {
        LOG.error("Exception looking up plugins for artifact {}", parentArtifactId, e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store.");
    }
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) ArtifactVersionRange(co.cask.cdap.api.artifact.ArtifactVersionRange) IOException(java.io.IOException) PluginEndpoint(co.cask.cdap.internal.app.runtime.plugin.PluginEndpoint) ArtifactSortOrder(co.cask.cdap.proto.artifact.ArtifactSortOrder) Predicate(com.google.common.base.Predicate) PluginNotExistsException(co.cask.cdap.internal.app.runtime.plugin.PluginNotExistsException) ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactDescriptor(co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor) PluginInfo(co.cask.cdap.proto.artifact.PluginInfo) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ArtifactId(co.cask.cdap.proto.id.ArtifactId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) PluginClass(co.cask.cdap.api.plugin.PluginClass) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

PluginEndpoint (co.cask.cdap.internal.app.runtime.plugin.PluginEndpoint)2 ArtifactSortOrder (co.cask.cdap.proto.artifact.ArtifactSortOrder)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 IOException (java.io.IOException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)1 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)1 ArtifactVersionRange (co.cask.cdap.api.artifact.ArtifactVersionRange)1 PluginClass (co.cask.cdap.api.plugin.PluginClass)1 ArtifactDescriptor (co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor)1 PluginNotExistsException (co.cask.cdap.internal.app.runtime.plugin.PluginNotExistsException)1 Id (co.cask.cdap.proto.Id)1 PluginInfo (co.cask.cdap.proto.artifact.PluginInfo)1 ArtifactId (co.cask.cdap.proto.id.ArtifactId)1 Predicate (com.google.common.base.Predicate)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1