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
}
}
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();
}
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());
}
}
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();
}
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();
}
Aggregations