Repository: lens
Updated Branches:
  refs/heads/master 09baa1288 -> e5691d8d6


http://git-wip-us.apache.org/repos/asf/lens/blob/e5691d8d/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 0748d5b..fb937c6 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
@@ -26,13 +26,17 @@ import javax.ws.rs.*;
 import javax.ws.rs.core.MediaType;
 import javax.xml.bind.JAXBElement;
 
-import org.apache.lens.api.*;
+import org.apache.lens.api.APIResult;
 import org.apache.lens.api.APIResult.*;
+import org.apache.lens.api.DateTime;
+import org.apache.lens.api.LensSessionHandle;
+import org.apache.lens.api.StringList;
 import org.apache.lens.api.metastore.*;
 import org.apache.lens.server.LensServices;
 import org.apache.lens.server.api.error.LensException;
 import org.apache.lens.server.api.metastore.CubeMetastoreService;
 
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
 
@@ -52,11 +56,11 @@ import lombok.extern.slf4j.Slf4j;
 public class MetastoreResource {
   public static final ObjectFactory X_CUBE_OBJECT_FACTORY = new 
ObjectFactory();
 
-  public CubeMetastoreService getSvc() {
+  public static CubeMetastoreService getSvc() {
     return LensServices.get().getService(CubeMetastoreService.NAME);
   }
 
-  private void checkSessionId(LensSessionHandle sessionHandle) {
+  private static void checkSessionId(LensSessionHandle sessionHandle) {
     if (sessionHandle == null) {
       throw new BadRequestException("Invalid session handle");
     }
@@ -75,6 +79,154 @@ public class MetastoreResource {
     checkNonNullArgs("One partition is null", 
partitions.getPartition().toArray());
   }
 
+  private static LensException processLensException(LensException exc) {
+    if (exc != null) {
+      exc.buildLensErrorTO(LensServices.get().getErrorCollection());
+    }
+    return exc;
+  }
+
+  public enum Entity {
+    DATABASE {
+      @Override
+      public List<String> doGetAll(LensSessionHandle sessionHandle) throws 
LensException {
+        return getSvc().getAllDatabases(sessionHandle);
+      }
+
+      @Override
+      public void doDelete(LensSessionHandle sessionid, String entityName, 
Boolean cascade) throws LensException {
+        if (cascade == null) {
+          throw new NotImplementedException();
+        } else {
+          getSvc().dropDatabase(sessionid, entityName, cascade);
+        }
+      }
+
+    }, STORAGE {
+      @Override
+      public List<String> doGetAll(LensSessionHandle sessionid) throws 
LensException {
+        return getSvc().getAllStorageNames(sessionid);
+      }
+
+      @Override
+      public void doDelete(LensSessionHandle sessionid, String entityName, 
Boolean cascade) throws LensException {
+        if (cascade == null) {
+          getSvc().dropStorage(sessionid, entityName);
+        } else {
+          throw new NotImplementedException();
+        }
+      }
+    }, CUBE {
+      @Override
+      public List<String> doGetAll(LensSessionHandle sessionHandle) throws 
LensException {
+        return getSvc().getAllCubeNames(sessionHandle);
+      }
+
+      @Override
+      public void doDelete(LensSessionHandle sessionid, String entityName, 
Boolean cascade) throws LensException {
+        if (cascade == null) {
+          getSvc().dropCube(sessionid, entityName);
+        } else {
+          throw new NotImplementedException();
+        }
+      }
+    }, FACT {
+      @Override
+      public List<String> doGetAll(LensSessionHandle sessionid) throws 
LensException {
+        return getSvc().getAllFactNames(sessionid, null);
+      }
+
+      @Override
+      public void doDelete(LensSessionHandle sessionid, String entityName, 
Boolean cascade) throws LensException {
+        if (cascade == null) {
+          throw new NotImplementedException();
+        } else {
+          getSvc().dropFactTable(sessionid, entityName, cascade);
+        }
+      }
+    }, DIMENSION {
+      @Override
+      public List<String> doGetAll(LensSessionHandle sessionid) throws 
LensException {
+        return getSvc().getAllDimensionNames(sessionid);
+      }
+
+      @Override
+      public void doDelete(LensSessionHandle sessionid, String entityName, 
Boolean cascade) throws LensException {
+        if (cascade == null) {
+          getSvc().dropDimension(sessionid, entityName);
+        } else {
+          throw new NotImplementedException();
+        }
+      }
+    }, DIMTABLE {
+      @Override
+      public List<String> doGetAll(LensSessionHandle sessionid) throws 
LensException {
+        return getSvc().getAllDimTableNames(sessionid, null);
+      }
+
+      @Override
+      public void doDelete(LensSessionHandle sessionid, String entityName, 
Boolean cascade) throws LensException {
+        if (cascade == null) {
+          throw new NotImplementedException();
+        } else {
+          getSvc().dropDimensionTable(sessionid, entityName, cascade);
+        }
+      }
+    };
+
+    public abstract List<String> doGetAll(LensSessionHandle sessionid) throws 
LensException;
+
+    public abstract void doDelete(LensSessionHandle sessionid, String 
entityName, Boolean cascade) throws LensException;
+
+    public StringList getAll(LensSessionHandle sessionid) {
+      checkSessionId(sessionid);
+      List<String> allNames;
+      try {
+        allNames = doGetAll(sessionid);
+      } catch (LensException e) {
+        throw new WebApplicationException(e);
+      }
+      return new StringList(allNames);
+    }
+
+    public APIResult delete(LensSessionHandle sessionid, String entityName, 
Boolean cascade) {
+      log.info("Drop {} {} cascade: {}", name(), entityName, cascade);
+      checkSessionId(sessionid);
+      try {
+        doDelete(sessionid, entityName, cascade);
+      } catch (LensException e) {
+        checkTableNotFound(e, entityName);
+        log.error("Error droping {} {}", name(), entityName, e);
+        return failure(processLensException(e));
+      }
+      return success();
+    }
+
+    public APIResult delete(LensSessionHandle sessionid, String entityName) {
+      return delete(sessionid, entityName, null);
+    }
+
+    public APIResult deleteAll(LensSessionHandle sessionid, Boolean cascade) {
+      checkSessionId(sessionid);
+      List<String> entities;
+      int numDeleted = 0;
+      int numExpected = 0;
+      LensException exc = null;
+      try {
+        entities = doGetAll(sessionid);
+        numExpected = entities.size();
+        for (String entity : entities) {
+          doDelete(sessionid, entity, cascade);
+          numDeleted++;
+        }
+      } catch (LensException e) {
+        log.error("Error deleting cubes:", e);
+        exc = e;
+      }
+      return successOrPartialOrFailure(numDeleted, numExpected, 
processLensException(exc));
+    }
+  }
+
   /**
    * API to know if metastore service is up and running
    *
@@ -96,14 +248,7 @@ public class MetastoreResource {
   @GET
   @Path("databases")
   public StringList getAllDatabases(@QueryParam("sessionid") LensSessionHandle 
sessionid) {
-    checkSessionId(sessionid);
-    List<String> allNames;
-    try {
-      allNames = getSvc().getAllDatabases(sessionid);
-    } catch (LensException e) {
-      throw new WebApplicationException(e);
-    }
-    return new StringList(allNames);
+    return Entity.DATABASE.getAll(sessionid);
   }
 
   /**
@@ -143,7 +288,7 @@ public class MetastoreResource {
       return success();
     } catch (LensException e) {
       log.error("Error changing current database", e);
-      return failure(e);
+      return failure(processLensException(e));
     }
   }
 
@@ -161,15 +306,7 @@ public class MetastoreResource {
   public APIResult dropDatabase(@QueryParam("sessionid") LensSessionHandle 
sessionid,
     @PathParam("dbName") String dbName,
     @QueryParam("cascade") boolean cascade) {
-    checkSessionId(sessionid);
-    log.info("Drop database {} cascade?{}", dbName, cascade);
-    try {
-      getSvc().dropDatabase(sessionid, dbName, cascade);
-      return success();
-    } catch (LensException e) {
-      log.error("Error dropping {}", dbName, e);
-      return failure(e);
-    }
+    return Entity.DATABASE.delete(sessionid, dbName, cascade);
   }
 
   /**
@@ -188,13 +325,12 @@ public class MetastoreResource {
     String dbName) {
     checkSessionId(sessionid);
     log.info("Create database {} Ignore Existing? {}", dbName, 
ignoreIfExisting);
-
     try {
       getSvc().createDatabase(sessionid, dbName, ignoreIfExisting);
       return success();
     } catch (LensException e) {
       log.error("Error creating database {}", dbName, e);
-      return failure(e);
+      return failure(processLensException(e));
     }
   }
 
@@ -265,15 +401,16 @@ public class MetastoreResource {
     @QueryParam("type") @DefaultValue("all") String cubeTypes) {
     checkSessionId(sessionid);
     try {
-      if (cubeTypes.equals("all")) {
+      switch (cubeTypes) {
+      case "all":
         return new StringList(getSvc().getAllCubeNames(sessionid));
-      } else if (cubeTypes.equals("base")) {
+      case "base":
         return new StringList(getSvc().getAllBaseCubeNames(sessionid));
-      } else if (cubeTypes.equals("derived")) {
+      case "derived":
         return new StringList(getSvc().getAllDerivedCubeNames(sessionid));
-      } else if (cubeTypes.equals("queryable")) {
+      case "queryable":
         return new StringList(getSvc().getAllQueryableCubeNames(sessionid));
-      } else {
+      default:
         throw new BadRequestException("Invalid type " + cubeTypes + " Accepted"
           + " values are 'all' or 'base' or 'derived' or 'queryable'");
       }
@@ -294,20 +431,7 @@ public class MetastoreResource {
   @Path("cubes")
   public APIResult deleteAllCubes(@QueryParam("sessionid") LensSessionHandle 
sessionid) {
     checkSessionId(sessionid);
-    List<String> cubeNames = null;
-    LensException exc = null;
-    int numDeleted = 0;
-    try {
-      cubeNames = getSvc().getAllCubeNames(sessionid);
-      for (String cubeName : cubeNames) {
-        getSvc().dropCube(sessionid, cubeName);
-        numDeleted++;
-      }
-    } catch (LensException e) {
-      log.error("Error deleting cubes:", e);
-      exc = e;
-    }
-    return successOrPartialOrFailure(numDeleted, cubeNames.size(), exc);
+    return Entity.CUBE.deleteAll(sessionid, null);
   }
 
   /**
@@ -330,13 +454,13 @@ public class MetastoreResource {
         checkTableNotFound(e, ((XDerivedCube) cube).getParent());
       }
       log.error("Error creating cube {}", cube.getName(), e);
-      return failure(e);
+      return failure(processLensException(e));
     }
     return success();
   }
 
 
-  private void checkTableNotFound(LensException e, String table) {
+  private static void checkTableNotFound(LensException e, String table) {
     List<String> messages = Lists.newArrayList();
     messages.add(e.getMessage());
     if (e.getCause() instanceof HiveException) {
@@ -372,7 +496,7 @@ public class MetastoreResource {
       }
       checkTableNotFound(e, cube.getName());
       log.error("Error updating cube {}", cube.getName(), e);
-      return failure(e);
+      return failure(processLensException(e));
     }
     return success();
   }
@@ -410,15 +534,7 @@ public class MetastoreResource {
   @Path("/cubes/{cubeName}")
   public APIResult dropCube(@QueryParam("sessionid") LensSessionHandle 
sessionid,
     @PathParam("cubeName") String cubeName) {
-    checkSessionId(sessionid);
-    try {
-      getSvc().dropCube(sessionid, cubeName);
-    } catch (LensException e) {
-      checkTableNotFound(e, cubeName);
-      log.error("Error droping cube {}", cubeName, e);
-      return failure(e);
-    }
-    return success();
+    return Entity.CUBE.delete(sessionid, cubeName, null);
   }
 
   /**
@@ -432,12 +548,7 @@ public class MetastoreResource {
   @Path("storages")
   public StringList getAllStorages(@QueryParam("sessionid") LensSessionHandle 
sessionid) {
     checkSessionId(sessionid);
-    try {
-      return new StringList(getSvc().getAllStorageNames(sessionid));
-    } catch (LensException e) {
-      log.error("Error getting storages", e);
-      throw new WebApplicationException(e);
-    }
+    return Entity.STORAGE.getAll(sessionid);
   }
 
   /**
@@ -456,7 +567,7 @@ public class MetastoreResource {
       getSvc().createStorage(sessionid, storage);
     } catch (LensException e) {
       log.error("Error creating storage {}", storage.getName(), e);
-      return failure(e);
+      return failure(processLensException(e));
     }
     return success();
   }
@@ -471,22 +582,7 @@ public class MetastoreResource {
   @DELETE
   @Path("storages")
   public APIResult deleteAllStorages(@QueryParam("sessionid") 
LensSessionHandle sessionid) {
-    checkSessionId(sessionid);
-    List<String> storageNames = null;
-    LensException exc = null;
-    int numDeleted = 0;
-    try {
-      storageNames = getSvc().getAllStorageNames(sessionid);
-      for (String storageName : storageNames) {
-        getSvc().dropStorage(sessionid, storageName);
-        numDeleted++;
-      }
-    } catch (LensException e) {
-      log.error("Error deleting storages:", e);
-      exc = e;
-    }
-    assert (numDeleted == storageNames.size() || exc != null);
-    return successOrPartialOrFailure(numDeleted, storageNames.size(), exc);
+    return Entity.STORAGE.deleteAll(sessionid, null);
   }
 
   /**
@@ -508,7 +604,7 @@ public class MetastoreResource {
     } catch (LensException e) {
       checkTableNotFound(e, storageName);
       log.error("Error updating storage {}", storageName, e);
-      return failure(e);
+      return failure(processLensException(e));
     }
     return success();
   }
@@ -545,15 +641,7 @@ public class MetastoreResource {
   @Path("/storages/{storage}")
   public APIResult dropStorage(@QueryParam("sessionid") LensSessionHandle 
sessionid,
     @PathParam("storage") String storageName) {
-    checkSessionId(sessionid);
-    try {
-      getSvc().dropStorage(sessionid, storageName);
-    } catch (LensException e) {
-      checkTableNotFound(e, storageName);
-      log.error("Error dropping storage {}", storageName, e);
-      return failure(e);
-    }
-    return success();
+    return Entity.STORAGE.delete(sessionid, storageName, null);
   }
 
   /**
@@ -566,13 +654,7 @@ public class MetastoreResource {
   @GET
   @Path("dimensions")
   public StringList getAllDimensionNames(@QueryParam("sessionid") 
LensSessionHandle sessionid) {
-    checkSessionId(sessionid);
-    try {
-      return new StringList(getSvc().getAllDimensionNames(sessionid));
-    } catch (LensException e) {
-      log.error("Error getting dimensions", e);
-      throw new WebApplicationException(e);
-    }
+    return Entity.DIMENSION.getAll(sessionid);
   }
 
   /**
@@ -591,7 +673,7 @@ public class MetastoreResource {
       getSvc().createDimension(sessionid, dimension);
     } catch (LensException e) {
       log.error("Error creating dimension {}", dimension.getName(), e);
-      return failure(e);
+      return failure(processLensException(e));
     }
     return success();
   }
@@ -606,21 +688,7 @@ public class MetastoreResource {
   @DELETE
   @Path("dimensions")
   public APIResult deleteAllDimensions(@QueryParam("sessionid") 
LensSessionHandle sessionid) {
-    checkSessionId(sessionid);
-    List<String> dimNames = null;
-    int numDeleted = 0;
-    LensException exc = null;
-    try {
-      dimNames = getSvc().getAllDimensionNames(sessionid);
-      for (String dimName : dimNames) {
-        getSvc().dropStorage(sessionid, dimName);
-        numDeleted++;
-      }
-    } catch (LensException e) {
-      log.error("Error deleting dimensions:", e);
-      exc = e;
-    }
-    return successOrPartialOrFailure(numDeleted, dimNames.size(), exc);
+    return Entity.DIMENSION.deleteAll(sessionid, null);
   }
 
   /**
@@ -642,7 +710,7 @@ public class MetastoreResource {
     } catch (LensException e) {
       checkTableNotFound(e, dimName);
       log.error("Error updating dimension {}", dimName, e);
-      return failure(e);
+      return failure(processLensException(e));
     }
     return success();
   }
@@ -679,15 +747,7 @@ public class MetastoreResource {
   @Path("/dimensions/{dimName}")
   public APIResult dropDimension(@QueryParam("sessionid") LensSessionHandle 
sessionid,
     @PathParam("dimName") String dimName) {
-    checkSessionId(sessionid);
-    try {
-      getSvc().dropDimension(sessionid, dimName);
-    } catch (LensException e) {
-      checkTableNotFound(e, dimName);
-      log.error("Error dropping dimension {}", dimName, e);
-      return failure(e);
-    }
-    return success();
+    return Entity.DIMENSION.delete(sessionid, dimName, null);
   }
 
   /**
@@ -742,7 +802,7 @@ public class MetastoreResource {
   @Path("/facts")
   public StringList getAllFacts(@QueryParam("sessionid") LensSessionHandle 
sessionid) throws LensException {
     checkSessionId(sessionid);
-    return new StringList(getSvc().getAllFactNames(sessionid, null));
+    return Entity.FACT.getAll(sessionid);
   }
 
   /**
@@ -758,21 +818,7 @@ public class MetastoreResource {
   @Path("facts")
   public APIResult deleteAllFacts(@QueryParam("sessionid") LensSessionHandle 
sessionid,
     @DefaultValue("false") @QueryParam("cascade") boolean cascade) {
-    checkSessionId(sessionid);
-    List<String> factNames = null;
-    int numDeleted = 0;
-    LensException exc = null;
-    try {
-      factNames = getSvc().getAllCubeNames(sessionid);
-      for (String factName : factNames) {
-        getSvc().dropFactTable(sessionid, factName, cascade);
-        numDeleted++;
-      }
-    } catch (LensException e) {
-      log.error("Error deleting cubes:", e);
-      exc = e;
-    }
-    return successOrPartialOrFailure(numDeleted, factNames.size(), exc);
+    return Entity.FACT.deleteAll(sessionid, cascade);
   }
 
   /**
@@ -816,7 +862,7 @@ public class MetastoreResource {
       getSvc().createFactTable(sessionid, fact);
     } catch (LensException exc) {
       log.error("Exception creating fact:", exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -841,7 +887,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, factName);
       log.error("Error updating fact {}", factName, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -861,15 +907,7 @@ public class MetastoreResource {
     @PathParam("factName") String factName,
     @DefaultValue("false") @QueryParam("cascade") boolean cascade)
     throws LensException {
-    checkSessionId(sessionid);
-    try {
-      getSvc().dropFactTable(sessionid, factName, cascade);
-    } catch (LensException exc) {
-      checkTableNotFound(exc, factName);
-      log.error("Error dropping fact {}", factName, exc);
-      return failure(exc);
-    }
-    return success();
+    return Entity.FACT.delete(sessionid, factName, cascade);
   }
 
   /**
@@ -911,7 +949,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, factName);
       log.error("Error dropping storages of fact {}", factName, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -936,7 +974,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, factName);
       log.error("Error adding storage to fact {}", factName, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -962,7 +1000,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, factName);
       log.error("Error dropping storage of fact {}", factName, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1032,7 +1070,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       log.warn("Got exception while dropping partition.", exc);
       checkTableNotFound(exc, factName);
-      return partial(exc);
+      return partial(processLensException(exc));
     }
     return success();
   }
@@ -1060,7 +1098,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, factName);
       log.error("Error adding partition to storage of fact {}:{}", factName, 
storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
   }
 
@@ -1088,7 +1126,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, factName);
       log.error("Error adding partition to storage of fact {}:{}", factName, 
storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1117,7 +1155,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, factName);
       log.error("Error adding partition to storage of fact {}:{}", factName, 
storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
   }
 
@@ -1145,7 +1183,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, factName);
       log.error("Error adding partition to storage of fact {}:{}", factName, 
storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1174,7 +1212,7 @@ public class MetastoreResource {
     } catch (LensException e) {
       checkTableNotFound(e, factName);
       log.error("Error dropping partition to storage of fact {}:{}", factName, 
storage, e);
-      return failure(e);
+      return failure(processLensException(e));
     }
     return success();
   }
@@ -1188,7 +1226,7 @@ public class MetastoreResource {
   @GET
   @Path("/dimtables")
   public StringList getAllDims(@QueryParam("sessionid") LensSessionHandle 
sessionid) throws LensException {
-    return new StringList(getSvc().getAllDimTableNames(sessionid, null));
+    return Entity.DIMTABLE.getAll(sessionid);
   }
 
   /**
@@ -1208,7 +1246,7 @@ public class MetastoreResource {
       getSvc().createDimensionTable(sessionid, dimensionTable);
     } catch (LensException exc) {
       log.error("Error creating cube dimension table {}", 
dimensionTable.getTableName(), exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1232,7 +1270,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, dimTableName);
       log.error("Error updating cube dimension table {}", dimTableName, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1251,15 +1289,7 @@ public class MetastoreResource {
   public APIResult dropDimensionTable(@QueryParam("sessionid") 
LensSessionHandle sessionid,
     @PathParam("dimTableName") String dimension,
     @QueryParam("cascade") boolean cascade) {
-    checkSessionId(sessionid);
-    try {
-      getSvc().dropDimensionTable(sessionid, dimension, cascade);
-    } catch (LensException e) {
-      checkTableNotFound(e, dimension);
-      log.error("Error dropping cube dimension table {}", dimension, e);
-      return failure(e);
-    }
-    return success();
+    return Entity.DIMTABLE.delete(sessionid, dimension, cascade);
   }
 
   /**
@@ -1320,7 +1350,7 @@ public class MetastoreResource {
     } catch (LensException e) {
       checkTableNotFound(e, dimTableName);
       log.error("Error creating dimension table storage {}:{}", dimTableName, 
storageTbl.getStorageName(), e);
-      return failure(e);
+      return failure(processLensException(e));
     }
     return success();
   }
@@ -1360,7 +1390,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, dimTableName);
       log.error("Error dropping storages of dimension table {}", dimTableName, 
exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1385,7 +1415,7 @@ public class MetastoreResource {
     } catch (LensException exc) {
       checkTableNotFound(exc, dimTableName);
       log.error("Error dropping storage of dimension table {}:{}", 
dimTableName, storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1434,7 +1464,7 @@ public class MetastoreResource {
       getSvc().dropPartitionFromStorageByFilter(sessionid, dimTableName, 
storage, filter);
     } catch (LensException exc) {
       log.error("Error dropping partition on storage of dimension table 
{}:{}", dimTableName, storage, exc);
-      return partial(exc);
+      return partial(processLensException(exc));
     }
     return success();
   }
@@ -1461,7 +1491,7 @@ public class MetastoreResource {
         values);
     } catch (LensException exc) {
       log.error("Error dropping partitions on storage of dimension table 
{}:{}", dimTableName, storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1489,7 +1519,7 @@ public class MetastoreResource {
         1);
     } catch (LensException exc) {
       log.error("Error adding partition to storage of dimension table {}:{}", 
dimTableName, storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
   }
 
@@ -1516,7 +1546,7 @@ public class MetastoreResource {
       getSvc().updatePartition(sessionid, dimTableName, storage, partition);
     } catch (LensException exc) {
       log.error("Error adding partition to storage of dimension table {}:{}", 
dimTableName, storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }
@@ -1544,7 +1574,7 @@ public class MetastoreResource {
         partitions.getPartition().size());
     } catch (LensException exc) {
       log.error("Error adding partition to storage of dimension table {}:{}", 
dimTableName, storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
   }
 
@@ -1571,7 +1601,7 @@ public class MetastoreResource {
       getSvc().updatePartitions(sessionid, dimTableName, storage, partitions);
     } catch (LensException exc) {
       log.error("Error adding partition to storage of dimension table {}:{}", 
dimTableName, storage, exc);
-      return failure(exc);
+      return failure(processLensException(exc));
     }
     return success();
   }

http://git-wip-us.apache.org/repos/asf/lens/blob/e5691d8d/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 e6a798a..5f9f639 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
@@ -477,9 +477,8 @@ public class TestMetastoreService extends LensJerseyTest {
       result = target.queryParam("sessionid", lensSessionId).request(
         mediaType).post(Entity.xml(cubeObjectFactory.createXCube(dcube)), 
APIResult.class);
       assertEquals(result.getStatus(), Status.FAILED);
-      assertEquals(result.getMessage(), "ERROR_IN_ENTITY_DEFINITION[Derived 
cube invalid: "
-        + "Measures [random_measure] and Dim Attributes "
-        + "[random_dim] were not present in parent cube testcube1]");
+      assertEquals(result.getMessage(), "Problem in submitting entity: Derived 
cube invalid: Measures "
+        + "[random_measure] and Dim Attributes [random_dim] were not present 
in parent cube testcube1");
       // create derived cube
       dcube = createDerivedCube("testderived", "testCube1", false);
       result = target.queryParam("sessionid", lensSessionId).request(
@@ -856,9 +855,8 @@ public class TestMetastoreService extends LensJerseyTest {
       result =
         target.queryParam("sessionid", 
lensSessionId).request(mediaType).post(Entity.xml(element), APIResult.class);
       assertEquals(result.getStatus(), Status.FAILED);
-      assertEquals(result.getMessage(), "ERROR_IN_ENTITY_DEFINITION[Derived 
cube invalid: "
-        + "Measures [random_measure] and Dim Attributes "
-        + "[random_dim] were not present in parent cube test_update]");
+      assertEquals(result.getMessage(), "Problem in submitting entity: Derived 
cube invalid: Measures "
+        + "[random_measure] and Dim Attributes [random_dim] were not present 
in parent cube test_update");
       dcube = createDerivedCube("test_update_derived", cubeName, false);
       // Create this cube first
       element = cubeObjectFactory.createXCube(dcube);
@@ -1960,14 +1958,15 @@ public class TestMetastoreService extends 
LensJerseyTest {
   private XPartition createPartition(String cubeTableName, Date partDate) {
     return createPartition(cubeTableName, partDate, "dt");
   }
-
-  private XPartition createPartition(String cubeTableName, Date partDate, 
final String timeDimension) {
-
+  private XTimePartSpecElement createTimePartSpecElement(Date partDate, String 
timeDimension) {
     XTimePartSpecElement timePart = 
cubeObjectFactory.createXTimePartSpecElement();
     timePart.setKey(timeDimension);
     
timePart.setValue(JAXBUtils.getXMLGregorianCalendar(HOURLY.truncate(partDate)));
+    return timePart;
+  }
+  private XPartition createPartition(String cubeTableName, Date partDate, 
final String timeDimension) {
 
-    return createPartition(cubeTableName, Arrays.asList(timePart));
+    return createPartition(cubeTableName, 
Arrays.asList(createTimePartSpecElement(partDate, timeDimension)));
   }
 
   private XPartition createPartition(String cubeTableName, final 
List<XTimePartSpecElement> timePartSpecs) {
@@ -2116,8 +2115,18 @@ public class TestMetastoreService extends LensJerseyTest 
{
         .post(null);
       Assert.assertEquals(resp.getStatus(), 400);
 
-      // Add a partition
+      // Add wrong partition
       final Date partDate = new Date();
+      XPartition xp2 = createPartition(table, partDate);
+      xp2.getTimePartitionSpec().getPartSpecElement()
+        .add(createTimePartSpecElement(partDate, "non_existant_time_part"));
+      partAddResult = 
target().path("metastore/facts/").path(table).path("storages/S2/partition")
+        .queryParam("sessionid", lensSessionId).request(mediaType)
+        .post(Entity.xml(cubeObjectFactory.createXPartition(xp2)), 
APIResult.class);
+      assertEquals(partAddResult.getStatus(), Status.FAILED);
+      assertEquals(partAddResult.getMessage(), "No timeline found for 
fact=testFactStoragePartitions, storage=S2, "
+        + "update period=HOURLY, partition column=non_existant_time_part.");
+      // Add a partition
       XPartition xp = createPartition(table, partDate);
       partAddResult = 
target().path("metastore/facts/").path(table).path("storages/S2/partition")
         .queryParam("sessionid", lensSessionId).request(mediaType)
@@ -2205,7 +2214,14 @@ public class TestMetastoreService extends LensJerseyTest 
{
         .post(Entity.xml(cubeObjectFactory.createXPartition(xp)));
       assertXMLError(resp);
 
-
+      // Try adding in batch with one partition being wrong wrt partition 
column.
+      partAddResult = 
target().path("metastore/facts/").path(table).path("storages/S2/partitions")
+        .queryParam("sessionid", lensSessionId).request(mediaType)
+        
.post(Entity.xml(cubeObjectFactory.createXPartitionList(toXPartitionList(xp2))),
+          APIResult.class);
+      assertEquals(partAddResult.getStatus(), Status.FAILED);
+      assertEquals(partAddResult.getMessage(), "No timeline found for 
fact=testFactStoragePartitions, storage=S2, "
+        + "update period=HOURLY, partition column=non_existant_time_part.");
       // Add in batch
       partAddResult = 
target().path("metastore/facts/").path(table).path("storages/S2/partitions")
         .queryParam("sessionid", lensSessionId).request(mediaType)

Reply via email to