Search in sources :

Example 21 with ArtifactNotFoundException

use of co.cask.cdap.common.ArtifactNotFoundException in project cdap by caskdata.

the class ArtifactClient method listVersions.

/**
   * Lists all versions of the given artifact in the given namespace.
   *
   * @param namespace the namespace to list artifact versions in
   * @param artifactName the name of the artifact
   * @param scope the scope of artifacts to get. If none is given, the scope defaults to the user scope
   * @return list of {@link ArtifactSummary}
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   * @throws ArtifactNotFoundException if the given artifact does not exist
   */
public List<ArtifactSummary> listVersions(NamespaceId namespace, String artifactName, @Nullable ArtifactScope scope) throws UnauthenticatedException, IOException, ArtifactNotFoundException, UnauthorizedException {
    URL url = scope == null ? config.resolveNamespacedURLV3(namespace, String.format("artifacts/%s", artifactName)) : config.resolveNamespacedURLV3(namespace, String.format("artifacts/%s?scope=%s", artifactName, scope.name()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ArtifactNotFoundException(namespace, artifactName);
    }
    return ObjectResponse.<List<ArtifactSummary>>fromJsonBody(response, ARTIFACT_SUMMARIES_TYPE).getResponseObject();
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) HttpResponse(co.cask.common.http.HttpResponse) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) URL(java.net.URL)

Aggregations

ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)21 HttpResponse (co.cask.common.http.HttpResponse)8 URL (java.net.URL)8 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)7 ArtifactId (co.cask.cdap.proto.id.ArtifactId)7 IOException (java.io.IOException)7 Test (org.junit.Test)7 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)6 BadRequestException (co.cask.cdap.common.BadRequestException)5 NamespaceId (co.cask.cdap.proto.id.NamespaceId)5 File (java.io.File)4 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)3 Plugin (co.cask.cdap.api.plugin.Plugin)3 PluginClass (co.cask.cdap.api.plugin.PluginClass)3 PluginPropertyField (co.cask.cdap.api.plugin.PluginPropertyField)3 SimpleProgramOptions (co.cask.cdap.internal.app.runtime.SimpleProgramOptions)3 ArtifactDetail (co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail)3 PluginNotExistsException (co.cask.cdap.internal.app.runtime.plugin.PluginNotExistsException)3 HttpRequest (co.cask.common.http.HttpRequest)3 ExecutionException (java.util.concurrent.ExecutionException)3