@PUT @Produces(MediaType.APPLICATION_JSON) public Space putSpace(Space space) throws NamespaceException, UserNotFoundException { SpaceConfig spaceConfig = PutSpaceResource.addOrUpdateSpace(namespaceService, spacePath, space); return Space.newInstance(spaceConfig, null, namespaceService.getDatasetCount(spacePath.toNamespaceKey(), BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH).getCount()); } }
@GET @Produces(MediaType.APPLICATION_JSON) public Space getSpace(@QueryParam("includeContents") @DefaultValue("true") boolean includeContents) throws Exception { try { final SpaceConfig config = namespaceService.getSpace(spacePath.toNamespaceKey()); final int datasetCount = namespaceService.getDatasetCount(spacePath.toNamespaceKey(), BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH).getCount(); NamespaceTree contents = includeContents ? newNamespaceTree(namespaceService.list(spacePath.toNamespaceKey())) : null; final Space space = newSpace(config, contents, datasetCount); return space; } catch (NamespaceNotFoundException nfe) { throw new SpaceNotFoundException(spacePath.getSpaceName().getName(), nfe); } }
@GET @Produces(MediaType.APPLICATION_JSON) public Home getHome(@QueryParam("includeContents") @DefaultValue("true") boolean includeContents) throws NamespaceException, HomeNotFoundException, DatasetNotFoundException { try { long dsCount = namespaceService.getDatasetCount(homePath.toNamespaceKey(), BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH).getCount(); final HomeConfig homeConfig = namespaceService.getHome(homePath.toNamespaceKey()).setExtendedConfig(new ExtendedConfig().setDatasetCount(dsCount)); Home home = newHome(homePath, homeConfig); if (includeContents) { home.setContents(newNamespaceTree(namespaceService.list(homePath.toNamespaceKey()))); } return home; } catch (NamespaceNotFoundException nfe) { throw new HomeNotFoundException(homePath.getHomeName(), nfe); } }
@GET @Produces(MediaType.APPLICATION_JSON) public Spaces getSpaces() throws Exception { final Spaces spaces = new Spaces(); for (SpaceConfig spaceConfig : namespaceService.getSpaces()) { int datasetCount = 0; try { datasetCount = namespaceService.getDatasetCount(new SpacePath(spaceConfig.getName()).toNamespaceKey(), BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH).getCount(); } catch (IllegalArgumentException e) { logger.warn("Could not load dataset count for {} because it has a invalid name: {}", spaceConfig.getName(), e.getMessage()); } catch (NamespaceException e) { logger.warn("Could not load dataset count for {}: {}", spaceConfig.getName(), e.getMessage()); } try { // we catch exceptions here so the user can still see their other Spaces spaces.add(newSpace(spaceConfig, datasetCount)); } catch (NamespaceNotFoundException e) { logger.warn("Skipping Space {} because namespace not found: {}", spaceConfig.getName(), e.getMessage()); } } return spaces; }
@GET public Sources getSources() throws Exception { final Sources sources = new Sources(); for (SourceConfig sourceConfig : sourceService.getSources()) { SourceUI source = newSource(sourceConfig); BoundedDatasetCount datasetCount = namespaceService.getDatasetCount(new NamespaceKey(source.getName()), BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH); source.setNumberOfDatasets(datasetCount.getCount()); source.setDatasetCountBounded(datasetCount.isCountBound() || datasetCount.isTimeBound()); SourceState state = sourceService.getStateForSource(sourceConfig); source.setState(state); sources.add(source); } return sources; }
@GET @Produces(MediaType.APPLICATION_JSON) public SourceUI getSource(@QueryParam("includeContents") @DefaultValue("true") boolean includeContents) throws Exception { try { final SourceConfig config = namespaceService.get().getSource(sourcePath.toNamespaceKey()); final SourceState sourceState = sourceService.getSourceState(sourcePath.getSourceName().getName()); if (sourceState == null) { throw new SourceNotFoundException(sourcePath.getSourceName().getName()); } final BoundedDatasetCount datasetCount = namespaceService.get().getDatasetCount(new NamespaceKey(config.getName()), BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH); final SourceUI source = newSource(config) .setNumberOfDatasets(datasetCount.getCount()); source.setDatasetCountBounded(datasetCount.isCountBound() || datasetCount.isTimeBound()); source.setState(sourceState); final AccelerationSettings settings = reflectionService.get().getReflectionSettings().getReflectionSettings(sourcePath.toNamespaceKey()); if (settings != null) { source.setAccelerationRefreshPeriod(settings.getRefreshPeriod()); source.setAccelerationGracePeriod(settings.getGracePeriod()); } if (includeContents) { source.setContents(sourceService.listSource(sourcePath.getSourceName(), namespaceService.get().getSource(sourcePath.toNamespaceKey()), securityContext.getUserPrincipal().getName())); } return source; } catch (NamespaceNotFoundException nfe) { throw new SourceNotFoundException(sourcePath.getSourceName().getName(), nfe); } }
final NamespaceKey sourceKey = new SourcePath(containerName).toNamespaceKey(); SourceConfig source = namespaceService.getSource(sourceKey); BoundedDatasetCount datasetCount = namespaceService.getDatasetCount(sourceKey, BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH); spaceInfo = SourceUI.get(source, connectionReader) .setNumberOfDatasets(datasetCount.getCount());
@Test public void testGetDatasetCount() throws Exception { try (final KVStoreProvider kvstore = new LocalKVStoreProvider(DremioTest.CLASSPATH_SCAN_RESULT, null, true, false)) { kvstore.start(); final NamespaceService ns = new NamespaceServiceImpl(kvstore); // create some nested datasets addSource(ns, "a"); for (int i = 0; i < 10; i++) { addDS(ns, "a.foo" + i); } for (int i = 0; i < 50; i++) { addDS(ns, "a.foo0.bar" + i); } for (int i = 0; i < 50; i++) { addDS(ns, "a.baz" + i); } // test count bound BoundedDatasetCount boundedDatasetCount = ns.getDatasetCount(new NamespaceKey("a"), 5000, 30); assertTrue(boundedDatasetCount.isCountBound()); assertEquals(boundedDatasetCount.getCount(), 30); // test time bound - the code checks every 50 children visited to see if the time bound has been hit and we give it 0 ms boundedDatasetCount = ns.getDatasetCount(new NamespaceKey("a"), 0, 1000); assertTrue(boundedDatasetCount.isTimeBound()); } }