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 void updateSpace(Space space, NamespaceAttribute... attributes) throws NamespaceException { NamespaceKey namespaceKey = new NamespaceKey(space.getName()); SpaceConfig spaceConfig = namespaceService.getSpace(namespaceKey); Preconditions.checkArgument(space.getName().equals(spaceConfig.getName()), "Space name is immutable."); namespaceService.addOrUpdateSpace(namespaceKey, getSpaceConfig(space), attributes); }
@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); } }
root = new ResourceTreeEntity(namespaceService.get().getSpace(new NamespaceKey(expandPathList.get(0)))); resources.add(root); } catch (NamespaceException nse) {
@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()); }
@AfterClass public static void after() throws Exception { NamespaceService namespaceService = newNamespaceService(); NamespaceKey namespaceKey = new NamespaceKey("searchSpace"); namespaceService.deleteSpace(namespaceKey, namespaceService.getSpace(namespaceKey).getTag()); }
} else if ("space".equals(type)) { final NamespaceKey spaceKey = new SpacePath(containerName).toNamespaceKey(); SpaceConfig space = namespaceService.getSpace(spaceKey); spaceInfo = newSpace(space, namespaceService.getAllDatasetsCount(spaceKey)); } else if ("source".equals(type)) {
@AfterClass public static void shutdown() throws Exception { // setup space NamespaceKey key = new NamespaceKey("dsvTest"); SpaceConfig space = newNamespaceService().getSpace(key); newNamespaceService().deleteSpace(key, space.getTag()); }
@AfterClass public static void shutdown() throws Exception { // setup space NamespaceKey key = new NamespaceKey("mySpace"); SpaceConfig space = newNamespaceService().getSpace(key); newNamespaceService().deleteSpace(key, space.getTag()); }
public void deleteSpace() { NamespaceKey key = new SpacePath(TEST_SPACE).toNamespaceKey(); SpaceConfig config; try { config = getNamespaceService().getSpace(key); if (config != null) { getNamespaceService().deleteSpace(key, config.getTag()); } }catch (NamespaceException e) { } }
namespaceService.getSpace(new SpacePath(new SpaceName(spaceConfig.getName())).toNamespaceKey());
public static SpaceConfig addOrUpdateSpace(NamespaceService service, SpacePath spacePath, Space space) throws NamespaceException, UserNotFoundException { SpaceConfig spaceConfig = new SpaceConfig() .setId(space.getId() != null ? new EntityId(space.getId()) : null) .setName(space.getName()) .setDescription(space.getDescription()) .setTag(space.getVersion()); service.addOrUpdateSpace(spacePath.toNamespaceKey(), spaceConfig); return service.getSpace(spacePath.toNamespaceKey()); }
public static void cleanup(DACDaemon dremioDaemon) throws Exception { final NamespaceService namespaceService = newNamespaceService(); namespaceService.deleteSpace(new SpacePath("testA").toNamespaceKey(), namespaceService.getSpace(new SpacePath("testA").toNamespaceKey()).getTag()); namespaceService.deleteSpace(new SpacePath("testB").toNamespaceKey(), namespaceService.getSpace(new SpacePath("testB").toNamespaceKey()).getTag()); }
@Test public void testVds() throws Exception { final String spaceName = "vds_space"; final String vdsName = "vds"; try { getNamespaceService().getSpace(new NamespaceKey(spaceName)); } catch (NamespaceNotFoundException e) { expectSuccess(getBuilder(getAPIv2().path("space/" + spaceName)) .buildPut(Entity.json(new Space(null, spaceName, null, null, null, 0, null))), Space.class); } final DatasetPath vdsPath = new DatasetPath(spaceName + "." + vdsName); final String vdsSql = String.format("SELECT * FROM dfs.\"%s\"", complexPdsPath); createDatasetFromSQLAndSave(vdsPath, vdsSql, Collections.emptyList()); final QueryProfile profile = getQueryProfile(String.format("SELECT * FROM %s.%s", spaceName, vdsName)); assertEquals(2, profile.getDatasetProfileCount()); assertTrue(containsPds(profile, complexSchema)); assertTrue(containsVds(profile, vdsSql)); }
@Test public void testJoinVds() throws Exception { final String spaceName = "vds_space2"; final String vdsName = "join_vds"; try { getNamespaceService().getSpace(new NamespaceKey(spaceName)); } catch (NamespaceNotFoundException e) { expectSuccess(getBuilder(getAPIv2().path("space/" + spaceName)) .buildPut(Entity.json(new Space(null, spaceName, null, null, null, 0, null))), Space.class); } final DatasetPath vdsPath = new DatasetPath(spaceName + "." + vdsName); final String vdsSql = String.format("SELECT * FROM dfs.\"%s\" t1 LEFT JOIN dfs.\"%s\" t2 ON t1.\"value\" = t2.custID", simplePdsPath, complexPdsPath); createDatasetFromSQLAndSave(vdsPath, vdsSql, Collections.emptyList()); final QueryProfile profile = getQueryProfile(String.format("SELECT * FROM %s.%s", spaceName, vdsName)); assertEquals(3, profile.getDatasetProfileCount()); assertTrue(containsPds(profile, simpleSchema)); assertTrue(containsPds(profile, complexSchema)); assertTrue(containsVds(profile, vdsSql)); }
@Test public void testSpace() throws Exception { // create a new space Space newSpace = new Space(null, "final frontier", null, null, null); Space space = expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH)).buildPost(Entity.json(newSpace)), new GenericType<Space>() {}); SpaceConfig spaceConfig = newNamespaceService().getSpace(new NamespaceKey(newSpace.getName())); assertEquals(space.getId(), spaceConfig.getId().getId()); assertEquals(space.getName(), spaceConfig.getName()); // make sure that trying to create the space again fails expectStatus(Response.Status.CONFLICT, getBuilder(getPublicAPI(3).path(CATALOG_PATH)).buildPost(Entity.json(newSpace))); // delete the space expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH).path(spaceConfig.getId().getId())).buildDelete()); thrown.expect(NamespaceException.class); newNamespaceService().getSpace(new NamespaceKey(spaceConfig.getName())); }
namespaceService.addOrUpdateSpace(new NamespaceKey(space1.getName()), space1); SpaceConfig newSpace1 = namespaceService.getSpace(new NamespaceKey(space1.getName())); Assert.assertEquals(space1, newSpace1); namespaceService.addOrUpdateSpace(new NamespaceKey(space2.getName()), space2); SpaceConfig newSpace2 = namespaceService.getSpace(new NamespaceKey(space2.getName())); Assert.assertEquals(space2, newSpace2); namespaceService.getSpace(new NamespaceKey("space3")); fail("getSource didn't throw exception"); } catch (NamespaceNotFoundException nfe) { namespaceService.addOrUpdateSpace(new NamespaceKey(space2.getName()), space2); assertEquals(space1, namespaceService.getSpace(new NamespaceKey("space1"))); assertEquals(space2, namespaceService.getSpace(new NamespaceKey("space2"))); namespaceService.getSpace(new NamespaceKey("space1")); fail("getSpace didn't throw exception"); } catch (NamespaceNotFoundException nfe) { namespaceService.getSpace(new NamespaceKey("space2")); fail("getSpace didn't throw exception"); } catch (NamespaceNotFoundException nfe) {
@Test public void testCTASReplace() throws Exception { NamespaceKey namespaceKey = new NamespaceKey("ctasSpace"); SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setName("ctasSpace"); newNamespaceService().addOrUpdateSpace(namespaceKey, spaceConfig); SqlQuery ctas = getQueryFromSQL("CREATE OR REPLACE VIEW ctasSpace.ctastest AS select * from (VALUES (1))"); Job ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .setQueryType(QueryType.UI_RUN) .build(), NoOpJobStatusListener.INSTANCE); waitForCompletion(ctasJob); ctas = getQueryFromSQL("CREATE OR REPLACE VIEW ctasSpace.ctastest AS select * from (VALUES (2))"); ctasJob = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .setQueryType(QueryType.UI_RUN) .build(), NoOpJobStatusListener.INSTANCE); waitForCompletion(ctasJob); newNamespaceService().deleteSpace(namespaceKey, newNamespaceService().getSpace(namespaceKey).getTag()); }