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