Repository: lens Updated Branches: refs/heads/master f3e6bc542 -> 20c1a53f4
http://git-wip-us.apache.org/repos/asf/lens/blob/20c1a53f/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java ---------------------------------------------------------------------- diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java b/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java index 1e11325..1b6b819 100644 --- a/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java +++ b/lens-server/src/main/java/org/apache/lens/server/metastore/JAXBUtils.java @@ -502,20 +502,20 @@ public final class JAXBUtils { return xpList; } - public static Set<XCubeSegment> xCubeSegmentsFromCubeSegments(Set<CubeSegment> segs) { - Set<XCubeSegment> xsegs = new HashSet<XCubeSegment>(); + public static Set<XSegment> xSegmentsFromSegments(Set<Segment> segs) { + Set<XSegment> xsegs = new HashSet<XSegment>(); if (segs != null && !segs.isEmpty()) { - for (CubeSegment seg : segs) { - XCubeSegment xcubeSeg = XCF.createXCubeSegment(); + for (Segment seg : segs) { + XSegment xcubeSeg = XCF.createXSegment(); xcubeSeg.setCubeName(seg.getName()); - xcubeSeg.setSegmentParameters(getXpropertiesFromCubeSegment(seg)); + xcubeSeg.setSegmentParameters(getXpropertiesFromSegment(seg)); xsegs.add(xcubeSeg); } } return xsegs; } - public static XProperties getXpropertiesFromCubeSegment(CubeSegment cseg) { + public static XProperties getXpropertiesFromSegment(Segment cseg) { XProperties xproperties = XCF.createXProperties(); for (String prop : cseg.getProperties().keySet()) { String segPrefix = MetastoreUtil.getSegmentPropertyKey(cseg.getName()); @@ -699,7 +699,7 @@ public final class JAXBUtils { mapFromXProperties(fact.getProperties())); } - public static CubeSegmentation cubeSegmentationFromXCubeSegmentation(XCubeSegmentation seg) throws LensException { + public static Segmentation segmentationFromXSegmentation(XSegmentation seg) throws LensException { Map<String, String> props = new HashMap<>(); // Skip properties with keyword internal. These properties are internal to lens @@ -709,9 +709,9 @@ public final class JAXBUtils { props.put(prop, mapFromXProperties(seg.getProperties()).get(prop)); } } - return new CubeSegmentation(seg.getCubeName(), + return new Segmentation(seg.getCubeName(), seg.getName(), - cubeSegmentsFromXCubeSegments(seg.getCubeSegements()), + segmentsFromXSegments(seg.getSegements()), seg.getWeight(), props); } @@ -731,18 +731,18 @@ public final class JAXBUtils { return fact; } - public static XCubeSegmentation xsegmentationFromCubeSegmentation(CubeSegmentation cSeg) { - XCubeSegmentation seg = XCF.createXCubeSegmentation(); + public static XSegmentation xsegmentationFromSegmentation(Segmentation cSeg) { + XSegmentation seg = XCF.createXSegmentation(); seg.setName(cSeg.getName()); seg.setProperties(new XProperties()); - seg.setCubeSegements(new XCubeSegments()); + seg.setSegements(new XSegments()); seg.setWeight(cSeg.weight()); seg.setCubeName(cSeg.getBaseCube()); if (xPropertiesFromMap(cSeg.getProperties()) != null) { seg.getProperties().getProperty().addAll(xPropertiesFromMap(cSeg.getProperties())); } - seg.getCubeSegements().getCubeSegment(). - addAll(xCubeSegmentsFromCubeSegments(cSeg.getCubeSegments())); + seg.getSegements().getSegment(). + addAll(xSegmentsFromSegments(cSeg.getSegments())); return seg; } @@ -843,16 +843,16 @@ public final class JAXBUtils { return storageTableMap; } - public static Set<CubeSegment> cubeSegmentsFromXCubeSegments(XCubeSegments segs) { - Set<CubeSegment> cubeSegs = new HashSet<>(); - for (XCubeSegment xcube : segs.getCubeSegment()){ + public static Set<Segment> segmentsFromXSegments(XSegments segs) { + Set<Segment> cubeSegs = new HashSet<>(); + for (XSegment xcube : segs.getSegment()){ Map<String, String> segProp = new HashMap<>(); if (xcube.getSegmentParameters() != null) { for (XProperty prop : xcube.getSegmentParameters().getProperty()) { segProp.put(prop.getName(), prop.getValue()); } } - cubeSegs.add(new CubeSegment(xcube.getCubeName(), segProp)); + cubeSegs.add(new Segment(xcube.getCubeName(), segProp)); } return cubeSegs; } http://git-wip-us.apache.org/repos/asf/lens/blob/20c1a53f/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java ---------------------------------------------------------------------- diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java b/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java index 7395c83..6f10d58 100644 --- a/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java +++ b/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java @@ -146,13 +146,13 @@ public class MetastoreResource { SEGMENTATION { @Override public List<String> doGetAll(LensSessionHandle sessionid) throws LensException { - return getSvc().getAllCubeSegmentations(sessionid, null); + return getSvc().getAllSegmentations(sessionid, null); } @Override public void doDelete(LensSessionHandle sessionid, String entityName, Boolean cascade) throws LensException { if (cascade == null) { - getSvc().dropCubeSegmentation(sessionid, entityName); + getSvc().dropSegmentation(sessionid, entityName); } else { throw new NotImplementedException(); } @@ -807,20 +807,20 @@ public class MetastoreResource { } /** - * Get all cube segmentations that belong to a cube in the metastore + * Get all segmentations that belong to a cube in the metastore * * @param sessionid The sessionid in which user is working * @param cubeName name of the base cube or derived cube - * @return List of {@link XCubeSegmentation} objects + * @return List of {@link XSegmentation} objects */ @GET - @Path("/cubes/{cubeName}/cubesegmentations") - public StringList getAllCubeSegmentationsOfCube( + @Path("/cubes/{cubeName}/segmentations") + public StringList getAllSegmentationsOfCube( @QueryParam("sessionid") LensSessionHandle sessionid, @PathParam("cubeName") String cubeName) throws LensException { checkSessionId(sessionid); try { - return new StringList(getSvc().getAllCubeSegmentations(sessionid, cubeName)); + return new StringList(getSvc().getAllSegmentations(sessionid, cubeName)); } catch (LensException exc) { checkTableNotFound(exc, cubeName); throw exc; @@ -843,14 +843,14 @@ public class MetastoreResource { /** - * Get all cube segmentations in the current database + * Get all segmentations in the current database * * @param sessionid The sessionid in which user is working - * @return StringList consisting of all cube segmentations + * @return StringList consisting of all segmentations */ @GET - @Path("/cubesegmentations") - public StringList getAllCubeSegmentations(@QueryParam("sessionid") LensSessionHandle sessionid) + @Path("/segmentations") + public StringList getAllSegmentations(@QueryParam("sessionid") LensSessionHandle sessionid) throws LensException { checkSessionId(sessionid); return Entity.SEGMENTATION.getAll(sessionid); @@ -874,15 +874,15 @@ public class MetastoreResource { } /** - * Delete all cube segmentations + * Delete all segmentations * * @param sessionid The sessionid in which user is working * @return APIResult with state {@link Status#SUCCEEDED} in case of successful delete. APIResult with state {@link * Status#FAILED} in case of delete failure. APIResult with state {@link Status#PARTIAL} in case of partial delete. */ @DELETE - @Path("cubesegmentations") - public APIResult deleteAllCubeSegmentations(@QueryParam("sessionid") LensSessionHandle sessionid) { + @Path("segmentations") + public APIResult deleteAllSegmentations(@QueryParam("sessionid") LensSessionHandle sessionid) { return Entity.SEGMENTATION.deleteAll(sessionid, null); } @@ -908,23 +908,23 @@ public class MetastoreResource { } /** - * Get the cube segmentation specified by name + * Get the segmentation specified by name * * @param sessionid The sessionid in which user is working - * @param cubeSegmentationName The cube segmentation name - * @return JAXB representation of {@link XCubeSegmentation} + * @param segmentationName The segmentation name + * @return JAXB representation of {@link XSegmentation} */ @GET - @Path("/cubesegmentations/{cubeSegmentationName}") - public JAXBElement<XCubeSegmentation> getCubeSegmentation(@QueryParam("sessionid") LensSessionHandle sessionid, - @PathParam("cubeSegmentationName") String cubeSegmentationName) + @Path("/segmentations/{segmentationName}") + public JAXBElement<XSegmentation> getSegmentation(@QueryParam("sessionid") LensSessionHandle sessionid, + @PathParam("segmentationName") String segmentationName) throws LensException { checkSessionId(sessionid); try { - return X_CUBE_OBJECT_FACTORY.createXCubeSegmentation(getSvc(). - getCubeSegmentation(sessionid, cubeSegmentationName)); + return X_CUBE_OBJECT_FACTORY.createXSegmentation(getSvc(). + getSegmentation(sessionid, segmentationName)); } catch (LensException exc) { - checkTableNotFound(exc, cubeSegmentationName); + checkTableNotFound(exc, segmentationName); throw exc; } } @@ -953,23 +953,23 @@ public class MetastoreResource { } /** - * Create a new cube segmentation + * Create a new segmentation * * @param sessionid The sessionid in which user is working - * @param seg The {@link XCubeSegmentation} representation of the cube segmentation + * @param seg The {@link XSegmentation} representation of the segmentation * @return {@link APIResult} with state {@link Status#SUCCEEDED}, if create was successful. {@link APIResult} with * state {@link Status#FAILED}, if create has failed */ @POST - @Path("/cubesegmentations") - public APIResult createCubeSegmentation(@QueryParam("sessionid") LensSessionHandle sessionid, XCubeSegmentation seg) + @Path("/segmentations") + public APIResult createSegmentation(@QueryParam("sessionid") LensSessionHandle sessionid, XSegmentation seg) throws LensException { checkSessionId(sessionid); try { - log.info("Create cube segmentation"); - getSvc().createCubeSegmentation(sessionid, seg); + log.info("Create segmentation"); + getSvc().createSegmentation(sessionid, seg); } catch (LensException exc) { - log.error("Exception creating cube segmentation:", exc); + log.error("Exception creating segmentation:", exc); return failure(processLensException(exc)); } return success(); @@ -1002,25 +1002,25 @@ public class MetastoreResource { } /** - * Update cube segmentation + * Update segmentation * * @param sessionid The sessionid in which user is working - * @param cubeSegmentationName name of cube segmentation - * @param seg The {@link XCubeSegmentation} representation of the updated fact table definition + * @param segmentationName name of segmentation + * @param seg The {@link XSegmentation} representation of the updated fact table definition * @return {@link APIResult} with state {@link Status#SUCCEEDED}, if update was successful. {@link APIResult} with * state {@link Status#FAILED}, if update has failed */ @PUT - @Path("/cubesegmentations/{cubeSegmentationName}") - public APIResult updateCubeSegmentation(@QueryParam("sessionid") LensSessionHandle sessionid, - @PathParam("cubeSegmentationName") String cubeSegmentationName, XCubeSegmentation seg) + @Path("/segmentations/{segmentationName}") + public APIResult updateSegmentation(@QueryParam("sessionid") LensSessionHandle sessionid, + @PathParam("segmentationName") String segmentationName, XSegmentation seg) throws LensException { checkSessionId(sessionid); try { - getSvc().updateCubeSegmentation(sessionid, seg); + getSvc().updateSegmentation(sessionid, seg); } catch (LensException exc) { - checkTableNotFound(exc, cubeSegmentationName); - log.error("Error updating segmentation {}", cubeSegmentationName, exc); + checkTableNotFound(exc, segmentationName); + log.error("Error updating segmentation {}", segmentationName, exc); return failure(processLensException(exc)); } return success(); @@ -1046,19 +1046,19 @@ public class MetastoreResource { /** - * Drop the cube segmentation, specified by name + * Drop the segmentation, specified by name * * @param sessionid The sessionid in which user is working - * @param cubeSegmentationName The cube segmentation name + * @param segmentationName The segmentation name * @return {@link APIResult} with state {@link Status#SUCCEEDED}, if drop was successful. {@link APIResult} with state * {@link Status#FAILED}, if drop has failed */ @DELETE - @Path("/cubesegmentations/{cubeSegmentationName}") - public APIResult dropCubeSegmentation(@QueryParam("sessionid") LensSessionHandle sessionid, - @PathParam("cubeSegmentationName") String cubeSegmentationName) + @Path("/segmentations/{segmentationName}") + public APIResult dropSegmentation(@QueryParam("sessionid") LensSessionHandle sessionid, + @PathParam("segmentationName") String segmentationName) throws LensException { - return Entity.SEGMENTATION.delete(sessionid, cubeSegmentationName, null); + return Entity.SEGMENTATION.delete(sessionid, segmentationName, null); } /** http://git-wip-us.apache.org/repos/asf/lens/blob/20c1a53f/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java ---------------------------------------------------------------------- diff --git a/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java b/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java index d5f5561..5424404 100644 --- a/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java +++ b/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java @@ -1633,12 +1633,12 @@ public class TestMetastoreService extends LensJerseyTest { } } - private XCubeSegmentation createCubeSegmentation(String segName) { - return createCubeSegmentation(segName, "testCube"); + private XSegmentation createSegmentation(String segName) { + return createSegmentation(segName, "testCube"); } - private XCubeSegmentation createCubeSegmentation(String segName, String cubeName) { - XCubeSegmentation seg = cubeObjectFactory.createXCubeSegmentation(); + private XSegmentation createSegmentation(String segName, String cubeName) { + XSegmentation seg = cubeObjectFactory.createXSegmentation(); //Create Xproperties XProperties props1 = cubeObjectFactory.createXProperties(); @@ -1653,24 +1653,24 @@ public class TestMetastoreService extends LensJerseyTest { prop2.setValue("prop_val2"); props2.getProperty().add(prop2); - // Create XcubeSegments - XCubeSegments cubes = new XCubeSegments(); - XCubeSegment c1 = cubeObjectFactory.createXCubeSegment(); + // Create XSegments + XSegments cubes = new XSegments(); + XSegment c1 = cubeObjectFactory.createXSegment(); c1.setCubeName("cube1"); c1.setSegmentParameters(props1); - XCubeSegment c2 = cubeObjectFactory.createXCubeSegment(); + XSegment c2 = cubeObjectFactory.createXSegment(); c2.setCubeName("cube2"); c2.setSegmentParameters(props2); - cubes.getCubeSegment().add(c1); - cubes.getCubeSegment().add(c2); + cubes.getSegment().add(c1); + cubes.getSegment().add(c2); seg.setProperties(new XProperties()); seg.setName(segName); seg.setWeight(10.0); seg.setCubeName(cubeName); - seg.setCubeSegements(cubes); + seg.setSegements(cubes); Map<String, String> properties = LensUtil.getHashMap("foo", "bar"); seg.getProperties().getProperty().addAll(JAXBUtils.xPropertiesFromMap(properties)); @@ -1678,44 +1678,44 @@ public class TestMetastoreService extends LensJerseyTest { } @Test(dataProvider = "mediaTypeData") - public void testCreateAndAlterCubeSegmentation(MediaType mediaType) throws Exception { - final String segname = "testCreateCubeSegmentation"; - final String DB = dbPFX + "testCreateCubeSegmentation_DB" + mediaType.getSubtype(); + public void testCreateAndAlterSegmentation(MediaType mediaType) throws Exception { + final String segname = "testCreateSegmentation"; + final String DB = dbPFX + "testCreateSegmentation_DB" + mediaType.getSubtype(); String prevDb = getCurrentDatabase(mediaType); createDatabase(DB, mediaType); setCurrentDatabase(DB, mediaType); try { - XCubeSegmentation seg = createCubeSegmentation(segname); + XSegmentation seg = createSegmentation(segname); APIResult result = target() .path("metastore") - .path("cubesegmentations").queryParam("sessionid", lensSessionId) + .path("segmentations").queryParam("sessionid", lensSessionId) .request(mediaType) .post(Entity.entity( - new GenericEntity<JAXBElement<XCubeSegmentation>>( - cubeObjectFactory.createXCubeSegmentation(seg)){}, mediaType), + new GenericEntity<JAXBElement<XSegmentation>>( + cubeObjectFactory.createXSegmentation(seg)){}, mediaType), APIResult.class); assertSuccess(result); - // Get all cube segmentations, this should contain the cube segmentation created earlier - StringList segNames = target().path("metastore/cubesegmentations") + // Get all segmentations, this should contain the segmentation created earlier + StringList segNames = target().path("metastore/segmentations") .queryParam("sessionid", lensSessionId).request(mediaType).get(StringList.class); assertTrue(segNames.getElements().contains(segname.toLowerCase())); - // Get the created cubesegmentation - JAXBElement<XCubeSegmentation> gotCubeSegmentation = target().path("metastore/cubesegmentations") + // Get the created segmentation + JAXBElement<XSegmentation> gotSegmentation = target().path("metastore/segmentations") .path(segname) .queryParam("sessionid", lensSessionId).request(mediaType) - .get(new GenericType<JAXBElement<XCubeSegmentation>>() {}); - XCubeSegmentation gotSeg = gotCubeSegmentation.getValue(); + .get(new GenericType<JAXBElement<XSegmentation>>() {}); + XSegmentation gotSeg = gotSegmentation.getValue(); assertTrue(gotSeg.getName().equalsIgnoreCase(segname)); assertEquals(gotSeg.getWeight(), 10.0); - CubeSegmentation cs = JAXBUtils.cubeSegmentationFromXCubeSegmentation(seg); + Segmentation cs = JAXBUtils.segmentationFromXSegmentation(seg); - // Check for cube segemnts + // Check for segemnts boolean foundCube1 = false; - for (CubeSegment cube : cs.getCubeSegments()) { + for (Segment cube : cs.getSegments()) { if (cube.getName().equalsIgnoreCase("cube1") && cube.getProperties().get("prop_key1").equals("prop_val1")) { foundCube1 = true; @@ -1725,40 +1725,40 @@ public class TestMetastoreService extends LensJerseyTest { assertTrue(foundCube1); assertEquals(cs.getProperties().get("foo"), "bar"); - // update cube segmentation - XCubeSegmentation update = JAXBUtils.xsegmentationFromCubeSegmentation(cs); - XCubeSegments cubes = new XCubeSegments(); - XCubeSegment c1 = cubeObjectFactory.createXCubeSegment(); + // update segmentation + XSegmentation update = JAXBUtils.xsegmentationFromSegmentation(cs); + XSegments cubes = new XSegments(); + XSegment c1 = cubeObjectFactory.createXSegment(); c1.setCubeName("cube11"); - XCubeSegment c2 = cubeObjectFactory.createXCubeSegment(); + XSegment c2 = cubeObjectFactory.createXSegment(); c2.setCubeName("cube22"); - cubes.getCubeSegment().add(c1); - cubes.getCubeSegment().add(c2); + cubes.getSegment().add(c1); + cubes.getSegment().add(c2); update.setWeight(20.0); - update.setCubeSegements(cubes); + update.setSegements(cubes); - result = target().path("metastore").path("cubesegmentations").path(segname) + result = target().path("metastore").path("segmentations").path(segname) .queryParam("sessionid", lensSessionId).request(mediaType) - .put(Entity.entity(new GenericEntity<JAXBElement<XCubeSegmentation>>( - cubeObjectFactory.createXCubeSegmentation(update)){}, mediaType), + .put(Entity.entity(new GenericEntity<JAXBElement<XSegmentation>>( + cubeObjectFactory.createXSegmentation(update)){}, mediaType), APIResult.class); assertSuccess(result); // Get the updated table - JAXBElement<XCubeSegmentation> gotUpdatedCubeSeg = target().path("metastore/cubesegmentations").path(segname) + JAXBElement<XSegmentation> gotUpdatedSeg = target().path("metastore/segmentations").path(segname) .queryParam("sessionid", lensSessionId).request(mediaType) - .get(new GenericType<JAXBElement<XCubeSegmentation>>() {}); - XCubeSegmentation gotUpSeg = gotUpdatedCubeSeg.getValue(); - CubeSegmentation usg = JAXBUtils.cubeSegmentationFromXCubeSegmentation(gotUpSeg); + .get(new GenericType<JAXBElement<XSegmentation>>() {}); + XSegmentation gotUpSeg = gotUpdatedSeg.getValue(); + Segmentation usg = JAXBUtils.segmentationFromXSegmentation(gotUpSeg); - assertEquals(usg.getCubeSegments().size(), 2); - for (CubeSegment segmnt : usg.getCubeSegments()) { + assertEquals(usg.getSegments().size(), 2); + for (Segment segmnt : usg.getSegments()) { assertTrue(segmnt.getName().equals("cube11") || segmnt.getName().equals("cube22")); } - // Finally, drop the cube segmentation - result = target().path("metastore").path("cubesegmentations").path(segname) + // Finally, drop the segmentation + result = target().path("metastore").path("segmentations").path(segname) .queryParam("sessionid", lensSessionId).request(mediaType) .delete(APIResult.class); @@ -1766,7 +1766,7 @@ public class TestMetastoreService extends LensJerseyTest { // Drop again, this time it should give a 404 try { - target().path("metastore").path("cubesegmentations").path(segname) + target().path("metastore").path("segmentations").path(segname) .queryParam("cascade", "true") .queryParam("sessionid", lensSessionId).request(mediaType) .delete(APIResult.class);
