@Override public SourceConfig getSource(String username, String sourcename) throws NamespaceException { return factoryProvider.get() .get(username) .getSource(new NamespaceKey(sourcename)); } }
private void verifySourceNotInNamespace(NamespaceService ns, NamespaceKey nsKey) throws NamespaceException { try { ns.getSource(nsKey); fail("getSource didn't throw exception"); } catch (NamespaceNotFoundException nfe) { } }
@RolesAllowed("admin") @DELETE @Produces(MediaType.APPLICATION_JSON) public void deleteSource(@QueryParam("version") String version) throws NamespaceException, SourceNotFoundException { if (version == null) { throw new ClientErrorException("missing version parameter"); } try { SourceConfig config = namespaceService.get().getSource(new SourcePath(sourceName).toNamespaceKey()); if(!Objects.equals(config.getTag(), version)) { throw new ConcurrentModificationException(String.format("Unable to delete source, expected version %s, received version %s.", config.getTag(), version)); } catalog.deleteSource(config); } catch (NamespaceNotFoundException nfe) { throw new SourceNotFoundException(sourcePath.getSourceName().getName(), nfe); } }
public void checkSourceExists(SourceName sourceName) throws SourceNotFoundException, NamespaceException { try { namespaceService.getSource(new SourcePath(sourceName).toNamespaceKey()); } catch (NamespaceNotFoundException nfe) { throw new SourceNotFoundException(sourceName.getName(), nfe); } }
public void unregisterSourceWithRuntime(SourceName sourceName) { final NamespaceKey key = new NamespaceKey(sourceName.getName()); try { SourceConfig config = namespaceService.getSource(key); createCatalog().deleteSource(config); reflectionServiceHelper.getReflectionSettings().removeSettings(key); } catch (NamespaceException e) { throw Throwables.propagate(e); } }
private void assertNoDatasetsAfterSourceDeletion() throws Exception { final SourceConfig sourceConfig = namespaceService.getSource(mockUpKey); namespaceService.deleteSource(mockUpKey, sourceConfig.getTag()); assertEquals(0, Iterables.size(namespaceService.getAllDatasets(mockUpKey))); }
/** * Synchronize the named source with the namespace. * @param name The name of the source to synchronize. * @param errorOnMissing Whether or not to throw an exception if the namespace does not contain the source. */ private ManagedStoragePlugin synchronize(String name, boolean errorOnMissing) { try{ logger.debug("Synchronizing source [{}] with namespace", name); SourceConfig config = systemNamespace.getSource(new NamespaceKey(name)); return synchronize(config); } catch (NamespaceNotFoundException ex) { if(!errorOnMissing) { return null; } throw UserException.validationError().message("Tried to access non-existent source [%s].", name).build(logger); } catch (Exception ex) { throw UserException.validationError(ex).message("Failure while trying to read source [%s].", name).build(logger); } }
@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); } }
} else if ("source".equals(type)) { 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)
final SourceConfig oldConfig = ns.getSource(nsKey); final SourceConfig updatedConfig = config;
public void deleteSource() { NamespaceKey key = new SourcePath(TEST_SOURCE).toNamespaceKey(); SourceConfig config; try { config = getNamespaceService().getSource(key); if (config != null) { getNamespaceService().deleteSource(key, config.getTag()); } } catch (NamespaceException e) { } }
if (!rootKey.equals(key)) { try { namespace.get().getSource(new NamespaceKey(key.getRoot()));
@AfterClass public static void shutdown() throws Exception { SourceConfig config = getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).getSource(new NamespaceKey("subPathDfs")); ((CatalogServiceImpl) getSabotContext().getCatalogService()).getSystemUserCatalog().deleteSource(config); } }
@AfterClass public static void removeMiniDfsBasedStorage() throws Exception { SourceConfig config = getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).getSource(new NamespaceKey(MINIDFS_STORAGE_PLUGIN_NAME)); ((CatalogServiceImpl) getSabotContext().getCatalogService()).getSystemUserCatalog().deleteSource(config); stopMiniDfsCluster(); } }
@AfterClass public static void removeMiniDfsBasedStorage() throws Exception { SourceConfig config = getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).getSource(new NamespaceKey(MINIDFS_STORAGE_PLUGIN_NAME)); ((CatalogServiceImpl) getSabotContext().getCatalogService()).getSystemUserCatalog().deleteSource(config); stopMiniDfsCluster(); } }
@AfterClass public static void removeMiniDfsBasedStorage() throws Exception { SourceConfig config = getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).getSource(new NamespaceKey(MINIDFS_STORAGE_PLUGIN_NAME)); ((CatalogServiceImpl) getSabotContext().getCatalogService()).getSystemUserCatalog().deleteSource(config); stopMiniDfsCluster(); } }
private SourceConfig registerSourceWithRuntime(SourceConfig sourceConfig, Catalog catalog, NamespaceAttribute... attributes) throws ExecutionSetupException, NamespaceException { if(sourceConfig.getTag() == null) { catalog.createSource(sourceConfig, attributes); } else { catalog.updateSource(sourceConfig, attributes); } final NamespaceKey key = new NamespaceKey(sourceConfig.getName()); reflectionServiceHelper.getReflectionSettings().setReflectionSettings(key, new AccelerationSettings() .setMethod(RefreshMethod.FULL) .setRefreshPeriod(sourceConfig.getAccelerationRefreshPeriod()) .setGracePeriod(sourceConfig.getAccelerationGracePeriod()) .setNeverExpire(sourceConfig.getAccelerationNeverExpire()) .setNeverRefresh(sourceConfig.getAccelerationNeverRefresh())); return namespaceService.getSource(key); }
@Test public void testSource() throws Exception { Source source = createSource(); // make sure we can fetch the source by id source = expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH).path(source.getId())).buildGet(), new GenericType<Source>() {}); // make sure that trying to create the source again fails NASConf nasConf = new NASConf(); nasConf.path = TestTools.getWorkingPath() + "/src/test/resources"; Source newSource = new Source(); newSource.setName("catalog-test"); newSource.setType("NAS"); newSource.setConfig(nasConf); expectStatus(Response.Status.CONFLICT, getBuilder(getPublicAPI(3).path(CATALOG_PATH)).buildPost(Entity.json(newSource))); // edit source source.setAccelerationRefreshPeriodMs(0); source = expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH).path(source.getId())).buildPut(Entity.json(source)), new GenericType<Source>() {}); assertEquals(source.getTag(), "1"); assertEquals((long) source.getAccelerationRefreshPeriodMs(), 0); // adding a folder to a source should fail Folder newFolder = new Folder(null, Arrays.asList(source.getName(), "myFolder"), null, null); expectStatus(Response.Status.BAD_REQUEST, getBuilder(getPublicAPI(3).path(CATALOG_PATH)).buildPost(Entity.json(newFolder))); // delete source expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH).path(source.getId())).buildDelete()); thrown.expect(NamespaceException.class); newNamespaceService().getSource(new NamespaceKey(source.getName())); }
@Test public void testPrivatesNoPrivateFields() throws Exception { final NASConf nasConf = new NASConf(); nasConf.path = "/mypath/"; SourceUI source = new SourceUI(); source.setConfig(nasConf); final NamespaceService namespaceService = newNamespaceService(); final NamespaceKey nameSpaceKey = new SourcePath("srcA").toNamespaceKey(); namespaceService.addOrUpdateSource(nameSpaceKey, source.asSourceConfig()); final SourceConfig config = namespaceService.getSource(nameSpaceKey); final ConnectionReader connectionReader = ConnectionReader.of(DremioTest.CLASSPATH_SCAN_RESULT, DremioTest.DEFAULT_SABOT_CONFIG); NASConf mySource = (NASConf) SourceUI.get(config, connectionReader).getConfig(); NASConf withPrivates = (NASConf) SourceUI.getWithPrivates(config, connectionReader).getConfig(); assertEquals(mySource, withPrivates); } }
@Test public void testPrivateFieldsSource() throws Exception { final SourceUI source = new SourceUI(); final APrivateSource priv = new APrivateSource(); priv.password = "ABC"; priv.username = "hello"; source.setConfig(priv); final NamespaceService namespaceService = newNamespaceService(); final NamespaceKey nameSpaceKey = new SourcePath("src").toNamespaceKey(); namespaceService.addOrUpdateSource(nameSpaceKey, source.asSourceConfig()); final SourceConfig config = namespaceService.getSource(nameSpaceKey); final ConnectionReader connectionReader = ConnectionReader.of(DremioTest.CLASSPATH_SCAN_RESULT, DremioTest.DEFAULT_SABOT_CONFIG); SourceUI mySource = SourceUI.get(config, connectionReader); APrivateSource myS3config = (APrivateSource) mySource.getConfig(); assertEquals(myS3config.password, ConnectionConf.USE_EXISTING_SECRET_VALUE); assertNotNull(myS3config.username); SourceUI withPrivatesSource = SourceUI.getWithPrivates(config, connectionReader); APrivateSource withPrivateS3Config = (APrivateSource) withPrivatesSource.getConfig(); assertNotNull(withPrivateS3Config.password); assertNotNull(withPrivateS3Config.username); assertEquals("ABC", withPrivateS3Config.password); assertEquals("hello", withPrivateS3Config.username); }