use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class SecureStoreClient method getKeyMetadata.
/**
* Get the metadata associated with the given secure key
*
* @param secureKeyId {@link SecureKeyId} secure key name
* @return {@link SecureStoreMetadata} metadata associated with the key
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws SecureKeyNotFoundException if secure key or the namespace is not found
*/
public SecureStoreMetadata getKeyMetadata(SecureKeyId secureKeyId) throws IOException, UnauthenticatedException, SecureKeyNotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(secureKeyId.getParent(), String.format("%s/metadata", getSecureKeyPath(secureKeyId)));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new SecureKeyNotFoundException(secureKeyId);
}
return GSON.fromJson(response.getResponseBodyAsString(), SecureStoreMetadata.class);
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class SecureStoreClient method deleteKey.
/**
* Delete the secure key
* @param secureKeyId {@link SecureKeyId} secure key name
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws SecureKeyNotFoundException if secure key or the namespace is not found
*/
public void deleteKey(SecureKeyId secureKeyId) throws IOException, UnauthenticatedException, SecureKeyNotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(secureKeyId.getParent(), getSecureKeyPath(secureKeyId));
HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new SecureKeyNotFoundException(secureKeyId);
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class ServiceClient method get.
/**
* Gets a {@link ServiceSpecification} for a {@link Service}.
*
* @param service ID of the service
* @return {@link ServiceSpecification} representing the service
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws NotFoundException if the app or service could not be found
*/
public ServiceSpecification get(ProgramId service) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s", service.getApplication(), service.getVersion(), service.getProgram()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(service);
}
return ObjectResponse.fromJsonBody(response, ServiceSpecification.class).getResponseObject();
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class DatasetClient method update.
/**
* Updates the properties of a dataset.
*
* @param instance the dataset to update
* @param properties properties to set
* @throws NotFoundException if the dataset is not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void update(DatasetId instance, Map<String, String> properties) throws NotFoundException, IOException, UnauthenticatedException, ConflictException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s/properties", instance.getDataset()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(properties)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(instance);
} else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
throw new ConflictException(response.getResponseBodyAsString());
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class DatasetClient method exists.
/**
* Checks if a dataset exists.
*
* @param instance the dataset to check
* @return true if the dataset exists
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public boolean exists(DatasetId instance) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s", instance.getDataset()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
return response.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND;
}
Aggregations