/** * 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); }
/** * 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); }
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
final Map<TableId, Future<?>> allFutures = new HashMap<>(); for (final NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) { impersonator.doAs(namespaceMeta.getNamespaceId(), new Callable<Void>() { @Override
@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(); } }
List<NamespaceMeta> namespaces = namespaceQueryAdmin.list(); for (final NamespaceMeta namespace : namespaces) { final NamespaceId namespaceId = namespace.getNamespaceId();
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())); } }