protected CatalogEntity createSpace(Space space, NamespaceAttribute... attributes) throws NamespaceException { String spaceName = space.getName(); Preconditions.checkArgument(space.getId() == null, "Space id is immutable."); Preconditions.checkArgument(spaceName != null, "Space name is required."); Preconditions.checkArgument(spaceName.trim().length() > 0, "Space name cannot be empty."); // TODO: move the space name validation somewhere reusable instead of having to create a new SpaceName new SpaceName(spaceName); NamespaceKey namespaceKey = new NamespaceKey(spaceName); // check if space already exists with the given name. if (namespaceService.exists(namespaceKey, NameSpaceContainer.Type.SPACE)) { throw new ConcurrentModificationException(String.format("A space with the name [%s] already exists.", spaceName)); } namespaceService.addOrUpdateSpace(namespaceKey, getSpaceConfig(space), attributes); return getSpaceFromConfig(namespaceService.getSpace(namespaceKey), null); }
protected CatalogEntity createDataset(Dataset dataset, NamespaceAttribute... attributes) throws NamespaceException { validateDataset(dataset); // only handle VDS Preconditions.checkArgument(dataset.getType() != Dataset.DatasetType.PHYSICAL_DATASET, "Physical Datasets can only be created by promoting other entities."); Preconditions.checkArgument(dataset.getId() == null, "Dataset id is immutable."); // verify we can save NamespaceKey topLevelKey = new NamespaceKey(dataset.getPath().get(0)); NamespaceKey parentNamespaceKey = new NamespaceKey(dataset.getPath().subList(0, dataset.getPath().size() - 1)); NamespaceKey namespaceKey = new NamespaceKey(dataset.getPath()); Preconditions.checkArgument(namespaceService.exists(parentNamespaceKey), String.format("Dataset parent path [%s] doesn't exist.", parentNamespaceKey.toString())); // can only create VDs in a space or home NameSpaceContainer entity = getNamespaceEntity(topLevelKey); List<NameSpaceContainer.Type> types = Arrays.asList(NameSpaceContainer.Type.SPACE, NameSpaceContainer.Type.HOME); Preconditions.checkArgument(types.contains(entity.getType()), "Virtual datasets can only be saved into spaces or home space."); sabotContext.getViewCreator(context.getUserPrincipal().getName()).createView(dataset.getPath(), dataset.getSql(), dataset.getSqlContext(), attributes); DatasetConfig created = namespaceService.getDataset(namespaceKey); return getDatasetFromConfig(created, null); }
public SourceConfig createSource(SourceConfig sourceConfig, NamespaceAttribute... attributes) throws ExecutionSetupException, NamespaceException, ResourceExistsException { validateSourceConfig(sourceConfig); Preconditions.checkArgument(sourceConfig.getId().getId() == null, "Source id is immutable."); Preconditions.checkArgument(sourceConfig.getTag() == null, "Source tag is immutable."); // check if source already exists with the given name. if (namespaceService.exists(new SourcePath(new SourceName(sourceConfig.getName())).toNamespaceKey(), SOURCE)) { throw new ResourceExistsException(String.format("A source with the name [%s] already exists.", sourceConfig.getName())); } sourceConfig.setCtime(System.currentTimeMillis()); return registerSourceWithRuntime(sourceConfig, attributes); }
@Test public void testCreateSpaceWithConflict() throws Exception { when(namespaceService.exists(any(NamespaceKey.class), eq(NameSpaceContainer.Type.SPACE))).thenReturn(true); // VDS Space space = new Space( null, "mySpace", null, 0L, null ); thrown.expect(ConcurrentModificationException.class); catalogServiceHelper.createCatalogItem(space); }
private static void createHomeDir(NamespaceService ns, String user) throws NamespaceException { final NamespaceKey homeKey = new HomePath(HomeName.getUserHomePath(user)).toNamespaceKey(); if (!ns.exists(homeKey, Type.HOME)) { final HomeConfig homeConfig = new HomeConfig().setOwner(user); ns.addOrUpdateHome(homeKey, homeConfig); } }
/** * Fetches a single item from the filesystem plugin */ public SchemaEntity get(List<String> path, String userName) { try { final FileStatus status = getFS(userName).getFileStatus(PathUtils.toFSPath(resolveTableNameToValidPath(path))); final Set<List<String>> tableNames = Sets.newHashSet(); final NamespaceService ns = context.getNamespaceService(userName); final NamespaceKey folderNSKey = new NamespaceKey(path); if (ns.exists(folderNSKey)) { for(NameSpaceContainer entity : ns.list(folderNSKey)) { if (entity.getType() == Type.DATASET) { tableNames.add(resolveTableNameToValidPath(entity.getDataset().getFullPathList())); } } } List<String> p = PathUtils.toPathComponents(status.getPath()); return getSchemaEntity(status, tableNames, p); } catch (IOException | NamespaceException e) { throw new RuntimeException(e); } }
@Test public void testCreateVDSInSourceShouldFail() throws Exception { when(namespaceService.exists(any(NamespaceKey.class))).thenReturn(true); // provide a source container NameSpaceContainer namespaceContainer = new NameSpaceContainer(); namespaceContainer.setType(NameSpaceContainer.Type.SOURCE); when(namespaceService.getEntities(Matchers.anyList())).thenReturn(Collections.singletonList(namespaceContainer)); // VDS needs sql Dataset dataset = new Dataset( null, Dataset.DatasetType.VIRTUAL_DATASET, Arrays.asList("source", "path"), null, null, null, null, "sql", null, null, null ); thrown.expect(IllegalArgumentException.class); catalogServiceHelper.createCatalogItem(dataset); }
@Test public void testCreateSpace() throws Exception { // VDS Space space = new Space( null, "mySpace", null, 0L, null ); when(namespaceService.exists(any(NamespaceKey.class))).thenReturn(false); when(namespaceService.getSpace(any(NamespaceKey.class))).thenReturn(catalogServiceHelper.getSpaceConfig(space)); CatalogEntity catalogItem = catalogServiceHelper.createCatalogItem(space); assertTrue(catalogItem instanceof Space); Space createdSpace = (Space) catalogItem; assertEquals(createdSpace.getName(), space.getName()); }
if (namespaceService.exists(filePath.toNamespaceKey())) { throw UserException.validationError() .message(format("File %s already exists", filePath.toPathString()))
@Test public void previewTableInSubschemaExposedAsTopLevelSchema() throws Exception { // Namespace is cleaned up before the test. So make sure to create a home directory for the test user. final NamespaceKey homeKey = new HomePath(HomeName.getUserHomePath(DEFAULT_USERNAME)).toNamespaceKey(); final NamespaceService ns = l(NamespaceService.class); if (!ns.exists(homeKey, Type.HOME)) { final HomeConfig homeConfig = new HomeConfig().setOwner(DEFAULT_USERNAME); ns.addOrUpdateHome(homeKey, homeConfig); } final NASConf nas = new NASConf(); nas.path = new File("src/test/resources").getAbsolutePath(); SourceUI source = new SourceUI(); source.setName("testNAS"); source.setConfig(nas); source.setMetadataPolicy(UIMetadataPolicy.of(CatalogService.DEFAULT_METADATA_POLICY_WITH_AUTO_PROMOTE)); final SourceService sourceService = newSourceService(); sourceService.registerSourceWithRuntime(source); InitialDataPreviewResponse resp = getPreview(new DatasetPath(asList("testNAS", "datasets", "users.json"))); // Now try to query the table as "testNAS.datasets"."users.json" createDatasetFromSQL("SELECT * FROM \"testNAS.datasets\".\"users.json\"", asList("cp")); }
public void addCPSource(boolean createFolder) throws Exception { getSourceService().registerSourceWithRuntime(InternalFileConf.create(TEST_SOURCE, new URI("classpath:///acceleration/"), SchemaMutability.ALL, CatalogService.DEFAULT_METADATA_POLICY)); final NamespaceService nsService = getNamespaceService(); final SpaceConfig config = new SpaceConfig().setName(TEST_SPACE); if(!nsService.exists(new SpacePath(config.getName()).toNamespaceKey())) { nsService.addOrUpdateSpace(new SpacePath(config.getName()).toNamespaceKey(), config); } if (createFolder) { final FolderConfig folderConfig = new FolderConfig().setName(TEST_FOLDER); nsService.addOrUpdateFolder(TEST_FOLDER_PATH.toNamespaceKey(), folderConfig); } }
assertEquals(tables1.size() + 1, tables2.size()); assertTrue(getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).exists( new NamespaceKey(PathUtils.parseFullPath("hive.\"default\".foo_bar")), Type.DATASET)); assertFalse(getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).exists( new NamespaceKey(PathUtils.parseFullPath("hive.foo_bar")), Type.DATASET)); .go(); assertFalse(getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).exists( new NamespaceKey(PathUtils.parseFullPath("hive.foo_bar")), Type.DATASET)); assertEquals(tables3.size() - 1, tables4.size()); assertFalse(getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).exists( new NamespaceKey(PathUtils.parseFullPath("hive.\"default\".foo_bar")), Type.DATASET)); assertFalse(getSabotContext().getNamespaceService(SystemUser.SYSTEM_USERNAME).exists( new NamespaceKey(PathUtils.parseFullPath("hive.foo_bar")), Type.DATASET));
final String inSpace = !jobRequest.getDatasetPathComponents().isEmpty() && namespaceService.exists(new NamespaceKey(jobRequest.getDatasetPathComponents().get(0)), NameSpaceContainer.Type.SPACE) ? jobRequest.getDatasetPathComponents().get(0) : null;