public static Space newInstance(SpaceConfig spaceConfig, NamespaceTree contents, int datasetCount) { String id = spaceConfig.getId() != null ? spaceConfig.getId().getId() : null; return new Space(id, spaceConfig.getName(), spaceConfig.getDescription(), spaceConfig.getTag(), contents, datasetCount, spaceConfig.getCtime()); } }
@BeforeClass public static void before() throws Exception { NamespaceService namespaceService = newNamespaceService(); SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setName("searchSpace"); namespaceService.addOrUpdateSpace(new NamespaceKey(spaceConfig.getName()), spaceConfig); }
public static SpaceConfig getSpaceConfig(Space space) { SpaceConfig config = new SpaceConfig(); config.setName(space.getName()); config.setId(new EntityId(space.getId())); if (space.getTag() != null) { config.setTag(space.getTag()); } config.setCtime(space.getCreatedAt()); return config; }
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()); }
@Test public void testGetSpaceCatalogEntityById() throws Exception { SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setId(new EntityId("space-id")); spaceConfig.setName("mySpace"); NameSpaceContainer namespaceContainer = new NameSpaceContainer(); namespaceContainer.setType(NameSpaceContainer.Type.SPACE); namespaceContainer.setSpace(spaceConfig); when(namespaceService.getEntityById(spaceConfig.getId().getId())).thenReturn(namespaceContainer); when(namespaceService.getEntities(Collections.singletonList(new NamespaceKey(spaceConfig.getName())))).thenReturn(Collections.singletonList(namespaceContainer)); // for children listing, we just send the space back to keep it simple when(namespaceService.list(new NamespaceKey(spaceConfig.getName()))).thenReturn(Collections.singletonList(namespaceContainer)); Optional<CatalogEntity> catalogEntityById = catalogServiceHelper.getCatalogEntityById(spaceConfig.getId().getId()); assertTrue(catalogEntityById.isPresent()); CatalogEntity catalogEntity = catalogEntityById.get(); assertTrue(catalogEntity instanceof Space); Space space = (Space) catalogEntity; assertEquals(space.getId(), spaceConfig.getId().getId()); assertEquals(space.getChildren().size(), 1); }
Stopwatch sw = Stopwatch.createStarted(); populateTestUsers(); SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setName("Prod-Sample"); spaceConfig.setDescription("production"); spaceConfig.setCtime(System.currentTimeMillis()); namespaceService.getSpace(new SpacePath(new SpaceName(spaceConfig.getName())).toNamespaceKey()); logger.info("Found " + spaceConfig.getName() + " space already created. Skipping sample dataset population. If" + " the sample datasets have been changed or if they were only partly constructed, clean the KV store and" + " restart the server."); namespaceService.addOrUpdateSpace(new SpacePath(new SpaceName(spaceConfig.getName())).toNamespaceKey(), spaceConfig); spaceConfig = new SpaceConfig(); spaceConfig.setName("Sales-Sample"); spaceConfig.setDescription("sales"); spaceConfig.setCtime(System.currentTimeMillis()); namespaceService.addOrUpdateSpace(new SpacePath(new SpaceName(spaceConfig.getName())).toNamespaceKey(), spaceConfig); spaceConfig = new SpaceConfig(); spaceConfig.setName("Tpch-Sample"); spaceConfig.setDescription("tpch queries"); spaceConfig.setCtime(System.currentTimeMillis()); namespaceService.addOrUpdateSpace(new SpacePath(new SpaceName(spaceConfig.getName())).toNamespaceKey(), spaceConfig); spaceConfig = new SpaceConfig(); spaceConfig.setName("DG"); spaceConfig.setDescription("dataset graph"); spaceConfig.setCtime(System.currentTimeMillis()); namespaceService.addOrUpdateSpace(new SpacePath(new SpaceName(spaceConfig.getName())).toNamespaceKey(), spaceConfig);
kvstore.start(); final NamespaceService namespaceService = new NamespaceServiceImpl(kvstore); final SpaceConfig space1 = new SpaceConfig(); final SpaceConfig space2 = new SpaceConfig(); space1.setName("space1"); space1.setCtime(1000L); namespaceService.addOrUpdateSpace(new NamespaceKey(space1.getName()), space1); SpaceConfig newSpace1 = namespaceService.getSpace(new NamespaceKey(space1.getName())); Assert.assertEquals(space1, newSpace1); space2.setName("space2"); space2.setCtime(2000L); namespaceService.addOrUpdateSpace(new NamespaceKey(space2.getName()), space2); SpaceConfig newSpace2 = namespaceService.getSpace(new NamespaceKey(space2.getName())); Assert.assertEquals(space2, newSpace2); space1.setCtime(2001L); space2.setCtime(2001L); namespaceService.addOrUpdateSpace(new NamespaceKey(space1.getName()), space1); namespaceService.addOrUpdateSpace(new NamespaceKey(space2.getName()), space2); namespaceService.deleteSpace(new NamespaceKey("space1"), space1.getTag()); try { namespaceService.getSpace(new NamespaceKey("space1")); namespaceService.deleteSpace(new NamespaceKey("space2"), space2.getTag());
public static void addSpace(NamespaceService ns, String name) throws Exception { final SpaceConfig space = new SpaceConfig(); space.setName(name); ns.addOrUpdateSpace(new NamespaceKey(name), space); }
SpaceConfig config = (SpaceConfig) object; String version = config.getTag();
private static CatalogItem fromSpaceConfig(SpaceConfig spaceConfig, CollaborationTag tags) { return new Builder() .setId(spaceConfig.getId().getId()) .setPath(Lists.newArrayList(spaceConfig.getName())) .setTag(String.valueOf(spaceConfig.getTag())) .setType(CatalogItemType.CONTAINER) .setContainerType(ContainerSubType.SPACE) .setTags(tags) .build(); }
@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()); }
@GET @Path("/spaces") @Produces(APPLICATION_JSON) public JobFilterItems searchSpaces(@QueryParam("filter") String query, @QueryParam("limit") Integer limit) throws NamespaceException { final JobFilterItems spaces = new JobFilterItems(); for (SpaceConfig spaceConfig : namespaceService.getSpaces()) { if (query == null || spaceConfig.getName().contains(query)) { spaces.add(new JobFilterItem(spaceConfig.getName(), spaceConfig.getName())); if (limit != null && spaces.getItems().size() >= limit) { break; } } } return spaces; }
@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())); }
public SpaceConfig newMessage() { return new SpaceConfig(); }
/** helper method that returns the id of the entity in given container */ public static String getId(NameSpaceContainer container) { EntityId entityId; switch (container.getType()) { case SOURCE: entityId = container.getSource().getId(); break; case SPACE: entityId = container.getSpace().getId(); break; case HOME: entityId = container.getHome().getId(); break; case FOLDER: entityId = container.getFolder().getId(); break; case DATASET: entityId = container.getDataset().getId(); break; default: throw new RuntimeException("Invalid container type"); } return entityId != null ? entityId.getId() : null; }
/** helper method that sets the given id in given container */ static void setId(NameSpaceContainer container, String id) { switch (container.getType()) { case SOURCE: container.getSource().setId(new EntityId(id)); return; case SPACE: container.getSpace().setId(new EntityId(id)); return; case HOME: container.getHome().setId(new EntityId(id)); return; case FOLDER: container.getFolder().setId(new EntityId(id)); return; case DATASET: container.getDataset().setId(new EntityId(id)); return; default: throw new RuntimeException("Invalid container type"); } }
@Override public void setTag(NameSpaceContainer value, String version) { switch (value.getType()) { case DATASET: value.getDataset().setTag(version); break; case FOLDER: value.getFolder().setTag(version); break; case HOME: value.getHome().setTag(version); break; case SOURCE: value.getSource().setTag(version); break; case SPACE: value.getSpace().setTag(version); break; default: throw new UnsupportedOperationException("Unknown type: " + value.getType()); } }
when(namespaceService.getHome(new HomePath(HomeName.getUserHomePath("user")).toNamespaceKey())).thenReturn(homeConfig); SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setName("mySpace"); spaceConfig.setId(new EntityId("space-id")); when(namespaceService.getSpaces()).thenReturn(Arrays.asList(spaceConfig)); assertEquals(item.getId(), spaceConfig.getId().getId());