use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteSparkManager method checkAvailability.
/**
* Checks if a user service is available by hitting the availability endpoint.
*/
private void checkAvailability() throws IOException, UnauthenticatedException, NotFoundException {
URL url = clientConfig.resolveNamespacedURLV3(programId.getNamespaceId(), String.format("apps/%s/versions/%s/%s/%s/available", programId.getApplication(), programId.getVersion(), programId.getType().getCategoryName(), programId.getProgram()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, clientConfig.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_UNAVAILABLE);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(programId);
}
if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) {
throw new ServiceUnavailableException(programId.toString());
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class AbstractNamespaceClient method delete.
@Override
public void delete(NamespaceId namespaceId) throws Exception {
URL url = resolve(String.format("unrecoverable/namespaces/%s", namespaceId.getNamespace()));
HttpResponse response = execute(HttpRequest.delete(url).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NamespaceNotFoundException(namespaceId);
} else if (HttpURLConnection.HTTP_FORBIDDEN == response.getResponseCode()) {
throw new NamespaceCannotBeDeletedException(namespaceId, response.getResponseBodyAsString());
} else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
throw new IOException(String.format("Cannot delete namespace %s. Reason: %s", namespaceId, response.getResponseBodyAsString()));
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class AbstractNamespaceClient method create.
@Override
public void create(NamespaceMeta metadata) throws Exception {
URL url = resolve(String.format("namespaces/%s", metadata.getName()));
HttpResponse response = execute(HttpRequest.put(url).withBody(GSON.toJson(metadata)).build());
String responseBody = response.getResponseBodyAsString();
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
if (responseBody.equals(String.format("Namespace '%s' already exists.", metadata.getName()))) {
throw new NamespaceAlreadyExistsException(metadata.getNamespaceId());
}
return;
}
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException("Bad request: " + responseBody);
}
throw new IOException(String.format("Cannot create namespace %s. Reason: %s", metadata.getName(), responseBody));
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class AbstractNamespaceClient method deleteDatasets.
@Override
public void deleteDatasets(NamespaceId namespaceId) throws Exception {
URL url = resolve(String.format("unrecoverable/namespaces/%s/datasets", namespaceId.getNamespace()));
HttpResponse response = execute(HttpRequest.delete(url).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NamespaceNotFoundException(namespaceId);
} else if (HttpURLConnection.HTTP_FORBIDDEN == response.getResponseCode()) {
String msg = String.format("Datasets in the namespace '%s' cannot be deleted. Reason: '%s'.", namespaceId, response.getResponseBodyAsString());
throw new NamespaceCannotBeDeletedException(namespaceId, msg);
} else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
throw new IOException(String.format("Cannot delete datasets in namespace %s. Reason: %s", namespaceId, response.getResponseBodyAsString()));
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class AbstractNamespaceClient method updateProperties.
@Override
public void updateProperties(NamespaceId namespaceId, NamespaceMeta metadata) throws Exception {
URL url = resolve(String.format("namespaces/%s/properties", namespaceId.getNamespace()));
HttpResponse response = execute(HttpRequest.put(url).withBody(GSON.toJson(metadata)).build());
String responseBody = response.getResponseBodyAsString();
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException("Bad request: " + responseBody);
}
throw new IOException(String.format("Cannot update namespace %s. Reason: %s", namespaceId, responseBody));
}
Aggregations