private NamespaceId validateAndGetScopedNamespace(NamespaceId namespace, ArtifactScope scope) throws NamespaceNotFoundException { try { namespaceQueryAdmin.get(namespace); } catch (NamespaceNotFoundException e) { throw e; } catch (Exception e) { // This can only happen when NamespaceAdmin uses HTTP to interact with namespaces. // Within AppFabric, NamespaceAdmin is bound to DefaultNamespaceAdmin which directly interacts with MDS. // Hence, this should never happen. throw Throwables.propagate(e); } return ArtifactScope.SYSTEM.equals(scope) ? NamespaceId.SYSTEM : namespace; }
/** * Returns a map of HBase to CDAP namespace. This is required when we want to report metrics for HBase tables where * it is run a separate service and reads the table metrics and reports it. There we need to translate the hbase * namespace to cdap namespace for metrics to make sense from CDAP perspective. This is also used during upgrade * step where we want to construct the correct {@link DatasetAdmin} for each dataset. * * @return map of hbase namespace to cdap namespace * @throws IOException if there was an error getting the {@link NamespaceMeta} of all the namespaces */ public Map<String, String> getHBaseToCDAPNamespaceMap() throws IOException { Map<String, String> reverseMap = new HashMap<>(); if (namespaceQueryAdmin == null) { throw new IOException("NamespaceQueryAdmin is not set and a reverseLookupMap was requested."); } try { List<NamespaceMeta> namespaceMetas = namespaceQueryAdmin.list(); for (NamespaceMeta namespaceMeta : namespaceMetas) { String hbaseNamespace = getHBaseNamespace(namespaceMeta); reverseMap.put(hbaseNamespace, namespaceMeta.getName()); } } catch (Exception ex) { throw new IOException("NamespaceQueryAdmin lookup to list all NamespaceMetas failed", ex); } return ImmutableMap.copyOf(reverseMap); }
@Override public boolean namespaceExists(String namespace) throws IOException { try { return namespaceQueryAdmin.exists(new NamespaceId(namespace)); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } } }
private NamespaceId validateAndGetNamespace(String namespace) throws NamespaceNotFoundException { NamespaceId namespaceId = new NamespaceId(namespace); try { namespaceQueryAdmin.get(namespaceId); } catch (NamespaceNotFoundException e) { throw e; } catch (Exception e) { // This can only happen when NamespaceAdmin uses HTTP to interact with namespaces. // Within AppFabric, NamespaceAdmin is bound to DefaultNamespaceAdmin which directly interacts with MDS. // Hence, this should never happen. throw Throwables.propagate(e); } return namespaceId; }
/** * Returns a map of HBase to CDAP namespace. This is required when we want to report metrics for HBase tables where * it is run a separate service and reads the table metrics and reports it. There we need to translate the hbase * namespace to cdap namespace for metrics to make sense from CDAP perspective. This is also used during upgrade * step where we want to construct the correct {@link DatasetAdmin} for each dataset. * * @return map of hbase namespace to cdap namespace * @throws IOException if there was an error getting the {@link NamespaceMeta} of all the namespaces */ public Map<String, String> getHBaseToCDAPNamespaceMap() throws IOException { Map<String, String> reverseMap = new HashMap<>(); if (namespaceQueryAdmin == null) { throw new IOException("NamespaceQueryAdmin is not set and a reverseLookupMap was requested."); } try { List<NamespaceMeta> namespaceMetas = namespaceQueryAdmin.list(); for (NamespaceMeta namespaceMeta : namespaceMetas) { String hbaseNamespace = getHBaseNamespace(namespaceMeta); reverseMap.put(hbaseNamespace, namespaceMeta.getName()); } } catch (Exception ex) { throw new IOException("NamespaceQueryAdmin lookup to list all NamespaceMetas failed", ex); } return ImmutableMap.copyOf(reverseMap); }
/** * 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); } }
private NamespaceId validateAndGetScopedNamespace(NamespaceId namespace, ArtifactScope scope) throws NamespaceNotFoundException { try { namespaceQueryAdmin.get(namespace); } catch (NamespaceNotFoundException e) { throw e; } catch (Exception e) { // This can only happen when NamespaceAdmin uses HTTP to interact with namespaces. // Within AppFabric, NamespaceAdmin is bound to DefaultNamespaceAdmin which directly interacts with MDS. // Hence, this should never happen. throw Throwables.propagate(e); } return ArtifactScope.SYSTEM.equals(scope) ? NamespaceId.SYSTEM : namespace; }
private void upgradeUserTables(final ExecutorService executor) throws Exception { final Map<String, Future<?>> allFutures = new HashMap<>(); final List<Closeable> toClose = new ArrayList<>(); for (final NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) { impersonator.doAs(namespaceMeta.getNamespaceId(), new Callable<Void>() { @Override
/** * 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 NamespaceId validateAndGetNamespace(String namespace) throws NamespaceNotFoundException { NamespaceId namespaceId = new NamespaceId(namespace); try { namespaceQueryAdmin.get(namespaceId); } catch (NamespaceNotFoundException e) { throw e; } catch (Exception e) { // This can only happen when NamespaceAdmin uses HTTP to interact with namespaces. // Within AppFabric, NamespaceAdmin is bound to DefaultNamespaceAdmin which directly interacts with MDS. // Hence, this should never happen. throw Throwables.propagate(e); } return namespaceId; }
final Map<TableId, Future<?>> allFutures = new HashMap<>(); for (final NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) { impersonator.doAs(namespaceMeta.getNamespaceId(), new Callable<Void>() { @Override
private void checkNamespaceExists(String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (!namespaceQueryAdmin.exists(namespaceId)) { throw new NamespaceNotFoundException(namespaceId); } }
@Override public Location get(NamespaceId namespaceId) throws IOException { if (isReservedNamespace(namespaceId)) { return getNonCustomMappedLocation(namespaceId); } // since this is not a cdap reserved namespace we look up meta if there is a custom mapping try { return get(namespaceQueryAdmin.get(namespaceId)); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(String.format("Failed to get namespace meta for namespace %s", namespaceId), e); } }
@Override public void collect() throws Exception { reset(); List<NamespaceMeta> namespaceMetas; namespaceMetas = nsQueryAdmin.list(); namespaces = namespaceMetas.size(); artifacts += artifactRepository.getArtifactSummaries(NamespaceId.SYSTEM, false).size(); for (NamespaceMeta meta : namespaceMetas) { List<ApplicationRecord> appRecords = appLifecycleService.getApps(meta.getNamespaceId(), Predicates.<ApplicationRecord>alwaysTrue()); apps += appRecords.size(); Set<ProgramType> programTypes = EnumSet.of(ProgramType.MAPREDUCE, ProgramType.SERVICE, ProgramType.SPARK, ProgramType.WORKER, ProgramType.WORKFLOW); for (ProgramType programType : programTypes) { programs += programLifecycleService.list(meta.getNamespaceId(), programType).size(); } artifacts += artifactRepository.getArtifactSummaries(meta.getNamespaceId(), false).size(); datasets += dsFramework.getInstances(meta.getNamespaceId()).size(); } }
@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); } } } }
@GET @Path("/") public void listStreams(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception { // Check for namespace existence. Throws NotFoundException if namespace doesn't exist namespaceQueryAdmin.get(new NamespaceId(namespaceId)); List<StreamSpecification> specifications = streamAdmin.listStreams(new NamespaceId(namespaceId)); List<StreamDetail> streamDetails = new ArrayList<>(specifications.size()); for (StreamSpecification specification : specifications) { streamDetails.add(new StreamDetail(specification.getName())); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(streamDetails)); }
List<NamespaceMeta> namespaces = namespaceQueryAdmin.list(); for (final NamespaceMeta namespace : namespaces) { final NamespaceId namespaceId = namespace.getNamespaceId();
/** * 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); } } } }
@Nullable // returns null iff the input is null private String getHiveDatabase(@Nullable String namespace) { // null namespace implies that the operation happens across all databases if (isNullOrDefault(namespace)) { return namespace; } try { String customHiveDb = namespaceQueryAdmin.get(new NamespaceId(namespace)).getConfig().getHiveDatabase(); if (!Strings.isNullOrEmpty(customHiveDb)) { return customHiveDb; } } catch (Exception e) { throw Throwables.propagate(e); } return getCDAPFormatDBName(namespace); }
public void reset() throws Exception { MockResponder responder; HttpRequest request; // delete all namespaces for (NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) { Id.Namespace namespace = Id.Namespace.from(namespaceMeta.getName()); responder = new MockResponder(); request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format( "%s/unrecoverable/namespaces/%s/datasets", Constants.Gateway.API_VERSION_3, namespace.getId())); namespaceHttpHandler.deleteDatasets(request, responder, namespaceMeta.getName()); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), String.format("could not delete datasets in namespace '%s'", namespace.getId())); responder = new MockResponder(); request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format("/v3/unrecoverable/namespaces/%s", namespace.getId())); namespaceHttpHandler.delete(request, responder, namespaceMeta.getName()); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), String.format("could not delete namespace '%s'", namespace.getId())); } }