@Override public NamespaceMeta get(final NamespaceId namespaceId) throws Exception { Iterable<NamespaceMeta> filtered = Iterables.filter(namespaces, new Predicate<NamespaceMeta>() { @Override public boolean apply(NamespaceMeta input) { return input.getName().equals(namespaceId.getNamespace()); } }); if (Iterables.size(filtered) == 0) { throw new NamespaceNotFoundException(namespaceId); } return filtered.iterator().next(); }
private NamespaceMeta fetchNamespaceMeta(NamespaceId namespaceId) throws Exception { NamespaceMeta ns = nsStore.get(namespaceId); if (ns == null) { throw new NamespaceNotFoundException(namespaceId); } return ns; }
private NamespaceMeta fetchNamespaceMeta(NamespaceId namespaceId) throws Exception { NamespaceMeta ns = nsStore.get(namespaceId); if (ns == null) { throw new NamespaceNotFoundException(namespaceId); } return ns; }
/** * Validates if secret manager is loaded and the provided namespace exists. */ private void validate(String namespace) throws Exception { if (secretManager == null) { throw new RuntimeException("Secret manager is either not initialized or not loaded. "); } NamespaceId namespaceId = new NamespaceId(namespace); if (!namespaceQueryAdmin.exists(namespaceId)) { throw new NamespaceNotFoundException(namespaceId); } }
@Override public synchronized NamespaceMeta get(NamespaceId namespaceId) throws Exception { NamespaceMeta meta = namespaces.get(namespaceId); if (meta == null) { throw new NamespaceNotFoundException(namespaceId); } return meta; }
@Override public synchronized void delete(NamespaceId namespaceId) throws Exception { if (namespaces.remove(namespaceId) == null) { throw new NamespaceNotFoundException(namespaceId); } }
/** * Throws an exception if the specified namespace is not the system namespace and does not exist */ private void ensureNamespaceExists(NamespaceId namespaceId) throws Exception { if (!NamespaceId.SYSTEM.equals(namespaceId)) { if (!namespaceQueryAdmin.exists(namespaceId)) { throw new NamespaceNotFoundException(namespaceId); } } }
private void checkNamespaceExists(String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (!namespaceQueryAdmin.exists(namespaceId)) { throw new NamespaceNotFoundException(namespaceId); } }
@Override public void ensureExists(NamespaceId namespaceId) throws NotFoundException { if (!NamespaceId.SYSTEM.equals(namespaceId)) { boolean exists = false; try { exists = namespaceQueryAdmin.exists(namespaceId); } catch (Exception e) { throw Throwables.propagate(e); } if (!exists) { throw new NamespaceNotFoundException(namespaceId); } } } }
/** * Throws an exception if the specified namespace is not the system namespace and does not exist */ private void ensureNamespaceExists(NamespaceId namespaceId) throws Exception { if (!NamespaceId.SYSTEM.equals(namespaceId)) { if (!namespaceQueryAdmin.exists(namespaceId)) { throw new NamespaceNotFoundException(namespaceId); } } } }
private void checkNamespaceExists(String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (!namespaceQueryAdmin.exists(namespaceId)) { throw new NamespaceNotFoundException(namespaceId); } }
/** * Throws an exception if the specified namespace is not the system namespace and does not exist */ private void ensureNamespaceExists(NamespaceId namespaceId) throws Exception { if (!NamespaceId.SYSTEM.equals(namespaceId)) { if (!namespaceQueryAdmin.exists(namespaceId)) { throw new NamespaceNotFoundException(namespaceId); } } }
@Override public void ensureExists(NamespaceId namespaceId) throws NotFoundException { if (!NamespaceId.SYSTEM.equals(namespaceId)) { boolean exists = false; try { exists = namespaceQueryAdmin.exists(namespaceId); } catch (Exception e) { throw Throwables.propagate(e); } if (!exists) { throw new NamespaceNotFoundException(namespaceId); } } } }
/** * Throws an exception if the specified namespace is not the system namespace and does not exist */ private void ensureNamespaceExists(NamespaceId namespaceId) throws Exception { if (!NamespaceId.SYSTEM.equals(namespaceId)) { if (!namespaceQueryAdmin.exists(namespaceId)) { throw new NamespaceNotFoundException(namespaceId); } } } }
@Override public synchronized void updateProperties(NamespaceId namespaceId, NamespaceMeta namespaceMeta) throws Exception { if (namespaces.replace(namespaceId, namespaceMeta) == null) { throw new NamespaceNotFoundException(namespaceId); } } }
@Override public NamespaceMeta get(NamespaceId namespaceId) throws Exception { HttpResponse response = execute(HttpRequest.get(resolve(String.format("namespaces/%s", namespaceId.getNamespace()))).build()); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NamespaceNotFoundException(namespaceId); } else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return ObjectResponse.fromJsonBody(response, NamespaceMeta.class).getResponseObject(); } throw new IOException(String.format("Cannot get namespace %s. Reason: %s", namespaceId, response.getResponseBodyAsString())); }
@Override public NamespaceMeta get(NamespaceId namespaceId) throws Exception { HttpResponse response = execute(HttpRequest.get(resolve(String.format("namespaces/%s", namespaceId.getNamespace()))).build()); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NamespaceNotFoundException(namespaceId); } else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return ObjectResponse.fromJsonBody(response, NamespaceMeta.class).getResponseObject(); } throw new IOException(String.format("Cannot get 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())); }
@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())); }
/** * Tests deploying an application in a non-existing non-default namespace. */ @Test public void testDeployNonExistingNamespace() throws Exception { HttpResponse response = deploy(AllProgramsApp.class, 404, Constants.Gateway.API_VERSION_3_TOKEN, "random"); NotFoundException nfe = new NamespaceNotFoundException(new NamespaceId("random")); Assert.assertEquals(nfe.getMessage(), response.getResponseBodyAsString()); }