Search in sources :

Example 11 with ArtifactNotFoundException

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

the class ArtifactClientTestRun method testNotFound.

@Test
public void testNotFound() throws Exception {
    ArtifactId ghostId = NamespaceId.DEFAULT.artifact("ghost", "1.0.0");
    try {
        artifactClient.list(new NamespaceId("ghost"));
        Assert.fail();
    } catch (NotFoundException e) {
    // expected
    }
    try {
        artifactClient.getArtifactInfo(ghostId);
        Assert.fail();
    } catch (ArtifactNotFoundException e) {
    // expected
    }
    try {
        artifactClient.listVersions(ghostId.getParent(), ghostId.getArtifact());
        Assert.fail();
    } catch (ArtifactNotFoundException e) {
    // expected
    }
    // test adding an artifact that extends a non-existent artifact
    Set<ArtifactRange> parents = Sets.newHashSet(new ArtifactRange(ghostId.getParent().getNamespace(), ghostId.getArtifact(), new ArtifactVersion("1"), new ArtifactVersion("2")));
    try {
        artifactClient.add(NamespaceId.DEFAULT, "abc", DUMMY_SUPPLIER, "1.0.0", parents);
        Assert.fail();
    } catch (NotFoundException e) {
    // expected
    }
    try {
        artifactClient.getPluginTypes(ghostId);
        Assert.fail();
    } catch (ArtifactNotFoundException e) {
    // expected
    }
    try {
        artifactClient.getPluginSummaries(ghostId, "type");
        Assert.fail();
    } catch (ArtifactNotFoundException e) {
    // expected
    }
    try {
        artifactClient.getPluginInfo(ghostId, "type", "name");
        Assert.fail();
    } catch (NotFoundException e) {
    // expected
    }
}
Also used : ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) Test(org.junit.Test)

Example 12 with ArtifactNotFoundException

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

the class ArtifactClient method getArtifactInfo.

/**
   * Gets information about a specific artifact version.
   *
   * @param artifactId the id of the artifact to get
   * @param scope the scope of the artifact
   * @return information about the given artifact
   * @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 ArtifactInfo getArtifactInfo(ArtifactId artifactId, ArtifactScope scope) throws IOException, UnauthenticatedException, ArtifactNotFoundException, UnauthorizedException {
    String path = String.format("artifacts/%s/versions/%s?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), scope.name());
    URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ArtifactNotFoundException(artifactId);
    }
    return ObjectResponse.fromJsonBody(response, ArtifactInfo.class, GSON).getResponseObject();
}
Also used : ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo) HttpResponse(co.cask.common.http.HttpResponse) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) URL(java.net.URL)

Example 13 with ArtifactNotFoundException

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

the class ArtifactClient method deleteProperty.

/**
   * Delete a property for an artifact. If the property does not exist, this will be a no-op.
   *
   * @param artifactId the artifact to delete a property from
   * @param key the property to delete
   * @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   * @throws ArtifactNotFoundException if the artifact does not exist
   * @throws IOException if a network error occurred
   */
public void deleteProperty(ArtifactId artifactId, String key) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException {
    String path = String.format("artifacts/%s/versions/%s/properties/%s", artifactId.getArtifact(), artifactId.getVersion(), key);
    URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
    HttpRequest.Builder requestBuilder = HttpRequest.delete(url);
    HttpRequest request = requestBuilder.build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
    int responseCode = response.getResponseCode();
    if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ArtifactNotFoundException(artifactId);
    } else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
        throw new BadRequestException(response.getResponseBodyAsString());
    }
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) HttpResponse(co.cask.common.http.HttpResponse) BadRequestException(co.cask.cdap.common.BadRequestException) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) URL(java.net.URL)

Example 14 with ArtifactNotFoundException

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

the class ArtifactClient method getPluginSummaries.

/**
   * Gets all the plugins of the given type available to the given artifact.
   *
   * @param artifactId the id of the artifact to get
   * @param pluginType the type of plugins to get
   * @param scope the scope of the artifact
   * @return list of {@link PluginSummary}
   * @throws ArtifactNotFoundException if the given artifact does not exist
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<PluginSummary> getPluginSummaries(ArtifactId artifactId, String pluginType, ArtifactScope scope) throws IOException, UnauthenticatedException, ArtifactNotFoundException, UnauthorizedException {
    String path = String.format("artifacts/%s/versions/%s/extensions/%s?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), pluginType, scope.name());
    URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ArtifactNotFoundException(artifactId);
    }
    return ObjectResponse.<List<PluginSummary>>fromJsonBody(response, PLUGIN_SUMMARIES_TYPE).getResponseObject();
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) PluginSummary(co.cask.cdap.proto.artifact.PluginSummary) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) URL(java.net.URL)

Example 15 with ArtifactNotFoundException

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

the class ArtifactClient method getPluginTypes.

/**
   * Gets all the plugin types available to a specific artifact.
   *
   * @param artifactId the id of the artifact to get
   * @param scope the scope of the artifact
   * @return list of plugin types available to the given artifact.
   * @throws ArtifactNotFoundException if the given artifact does not exist
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<String> getPluginTypes(ArtifactId artifactId, ArtifactScope scope) throws IOException, UnauthenticatedException, ArtifactNotFoundException, UnauthorizedException {
    String path = String.format("artifacts/%s/versions/%s/extensions?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), scope.name());
    URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ArtifactNotFoundException(artifactId);
    }
    return ObjectResponse.<List<String>>fromJsonBody(response, EXTENSIONS_TYPE).getResponseObject();
}
Also used : 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