/** * Creates secure {@link HBaseMetadataService} which delegates to {@link Admin} instantiated with default * {@link HBaseConfiguration} and {@code hbase-site.xml} properties overridden with the config * for the cluster imported in the service pool (either manually or using Ambari) */ public static HBaseMetadataService newInstance(EnvironmentService environmentService, Long clusterId, SecurityContext securityContext, Subject subject) throws IOException, EntityNotFoundException { return newInstance( overrideConfig(HBaseConfiguration.create(), environmentService, clusterId), securityContext, subject, getHbaseMasterComponent(environmentService, clusterId), getHbaseMasterComponentProcesses(environmentService, clusterId)); }
@GET @Path("/clusters/{clusterId}/services/hbase/tables") @Timed public Response getTablesByClusterId(@PathParam("clusterId") Long clusterId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, clusterId, READ); try (HBaseMetadataService hbaseMetadataService = HBaseMetadataService .newInstance(environmentService, clusterId, securityContext, subject)) { return WSUtils.respondEntity(Subject.doAs(subject, (PrivilegedExceptionAction<Tables>) hbaseMetadataService::getHBaseTables), OK); } catch (EntityNotFoundException ex) { throw com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException.byId(ex.getMessage()); } }
@GET @Path("/clusters/{clusterId}/services/hbase/namespaces/{namespace}/tables") @Timed public Response getNamespaceTablesByClusterId(@PathParam("clusterId") Long clusterId, @PathParam("namespace") String namespace, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, clusterId, READ); try (HBaseMetadataService hbaseMetadataService = HBaseMetadataService .newInstance(environmentService, clusterId, securityContext, subject)) { return WSUtils.respondEntity(Subject.doAs(subject, (PrivilegedExceptionAction<Tables>)() -> hbaseMetadataService.getHBaseTables(namespace)), OK); } catch (EntityNotFoundException ex) { throw com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException.byId(ex.getMessage()); } } }
@Override public Map<String, Object> getHintsOnCluster(Cluster cluster, SecurityContext securityContext, Subject subject) { Map<String, Object> hintMap = new HashMap<>(); try (HBaseMetadataService hBaseMetadataService = HBaseMetadataService.newInstance(environmentService, cluster.getId(), securityContext, subject)) { hintMap.put(FIELD_NAME_TABLE, hBaseMetadataService.getHBaseTables().getTables()); } catch (ServiceNotFoundException e) { // we access it from mapping information so shouldn't be here throw new IllegalStateException("Service " + Constants.HBase.SERVICE_NAME + " in cluster " + cluster.getName() + " not found but mapping information exists."); } catch (ServiceConfigurationNotFoundException e) { // there's HBASE service but not enough configuration info. } catch (Exception e) { throw new RuntimeException(e); } return hintMap; }
@GET @Path("/clusters/{clusterId}/services/hbase/namespaces") @Timed public Response getNamespacesByClusterId(@PathParam("clusterId") Long clusterId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, clusterId, READ); try (HBaseMetadataService hbaseMetadataService = HBaseMetadataService .newInstance(environmentService, clusterId, securityContext, subject)) { return WSUtils.respondEntity(hbaseMetadataService.getHBaseNamespaces(), OK); } catch (EntityNotFoundException ex) { throw com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException.byId(ex.getMessage()); } }