public DatabaseBuilder setCatalogName(Catalog catalog) { this.catalogName = catalog.getName(); return this; }
public void addCatalogToCache(Catalog cat) { try { cacheLock.writeLock().lock(); Catalog catCopy = cat.deepCopy(); // ObjectStore also stores db name in lowercase catCopy.setName(catCopy.getName().toLowerCase()); catalogCache.put(cat.getName(), catCopy); isCatalogCacheDirty.set(true); } finally { cacheLock.writeLock().unlock(); } }
public void populateCatalogsInCache(Collection<Catalog> catalogs) { for (Catalog cat : catalogs) { Catalog catCopy = cat.deepCopy(); // ObjectStore also stores db name in lowercase catCopy.setName(catCopy.getName().toLowerCase()); try { cacheLock.writeLock().lock(); // Since we allow write operations on cache while prewarm is happening: // 1. Don't add databases that were deleted while we were preparing list for prewarm // 2. Skip overwriting exisiting db object // (which is present because it was added after prewarm started) if (catalogsDeletedDuringPrewarm.contains(catCopy.getName())) { continue; } catalogCache.putIfAbsent(catCopy.getName(), catCopy); catalogsDeletedDuringPrewarm.clear(); isCatalogCachePrewarmed = true; } finally { cacheLock.writeLock().unlock(); } } }
public DropCatalogMessage buildDropCatalogMessage(Catalog catalog) { return new JSONDropCatalogMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, catalog.getName(), now()); }
public CreateCatalogMessage buildCreateCatalogMessage(Catalog catalog) { return new JSONCreateCatalogMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, catalog.getName(), now()); }
public Object getFieldValue(_Fields field) { switch (field) { case NAME: return getName(); case DESCRIPTION: return getDescription(); case LOCATION_URI: return getLocationUri(); case CREATE_TIME: return getCreateTime(); } throw new IllegalStateException(); }
/** * Filter the catalog if filtering is enabled; Otherwise, return original object * @param isFilterEnabled true: filtering is enabled; false: filtring is disabled. * @param filterHook: the object that does filtering * @param catalog: the catalog object * @return the catalog object that current user has access or filtering is disabled; * Otherwise, throw NoSuchObjectException * @throws MetaException * @throws NoSuchObjectException */ public static Catalog filterCatalogIfEnabled( boolean isFilterEnabled, MetaStoreFilterHook filterHook, Catalog catalog ) throws MetaException, NoSuchObjectException { if (isFilterEnabled) { Catalog filteredCatalog = filterHook.filterCatalog(catalog); if (filteredCatalog == null) { throw new NoSuchObjectException("Catalog " + catalog.getName() + " not found."); } } return catalog; }
@Override public void createCatalog(Catalog cat) throws MetaException { LOG.debug("Creating catalog " + cat.getName()); boolean committed = false; MCatalog mCat = catToMCat(cat); try { openTransaction(); pm.makePersistent(mCat); committed = commitTransaction(); } finally { if (!committed) { rollbackTransaction(); } } }
/** * Build the database path based on catalog name and database name. This should only be used * when a database is being created or altered. If you just want to find out the path a * database is already using call {@link #getDatabasePath(Database)}. If the passed in * database already has a path set that will be used. If not the location will be built using * catalog's path and the database name. * @param cat catalog the database is in * @param db database object * @return Path representing the directory for the database * @throws MetaException when the file path cannot be properly determined from the configured * file system. */ public Path determineDatabasePath(Catalog cat, Database db) throws MetaException { if (db.isSetLocationUri()) { return getDnsPath(new Path(db.getLocationUri())); } if (cat == null || cat.getName().equalsIgnoreCase(DEFAULT_CATALOG_NAME)) { if (db.getName().equalsIgnoreCase(DEFAULT_DATABASE_NAME)) { return getWhRoot(); } else { return new Path(getWhRoot(), dbDirFromDbName(db)); } } else { return new Path(getDnsPath(new Path(cat.getLocationUri())), dbDirFromDbName(db)); } }
@VisibleForTesting public static void createDefaultCatalog(RawStore ms, Warehouse wh) throws MetaException, InvalidOperationException { try { Catalog defaultCat = ms.getCatalog(DEFAULT_CATALOG_NAME); // Null check because in some test cases we get a null from ms.getCatalog. if (defaultCat !=null && defaultCat.getLocationUri().equals("TBD")) { // One time update issue. When the new 'hive' catalog is created in an upgrade the // script does not know the location of the warehouse. So we need to update it. LOG.info("Setting location of default catalog, as it hasn't been done after upgrade"); defaultCat.setLocationUri(wh.getWhRoot().toString()); ms.alterCatalog(defaultCat.getName(), defaultCat); } } catch (NoSuchObjectException e) { Catalog cat = new Catalog(DEFAULT_CATALOG_NAME, wh.getWhRoot().toString()); long time = System.currentTimeMillis() / 1000; cat.setCreateTime((int) time); cat.setDescription(Warehouse.DEFAULT_CATALOG_COMMENT); ms.createCatalog(cat); } }
try { try { getMS().getCatalog(catalog.getName()); throw new AlreadyExistsException("Catalog " + catalog.getName() + " already exists"); } catch (NoSuchObjectException e) { if (!MetaStoreUtils.validateName(catalog.getName(), null)) { throw new InvalidObjectException(catalog.getName() + " is not a valid catalog name"); if (!wh.mkdirs(catPath)) { throw new MetaException("Unable to create catalog path " + catPath + ", failed to create catalog " + catalog.getName()); "Default database for catalog " + catalog.getName(), catalog.getLocationUri(), Collections.emptyMap()); db.setCatalogName(catalog.getName()); create_database_core(ms, db);
@Override public void alterCatalog(String catName, Catalog cat) throws MetaException, InvalidOperationException { if (!cat.getName().equals(catName)) { throw new InvalidOperationException("You cannot change a catalog's name"); } boolean committed = false; try { MCatalog mCat = getMCatalog(catName); if (org.apache.commons.lang.StringUtils.isNotBlank(cat.getLocationUri())) { mCat.setLocationUri(cat.getLocationUri()); } if (org.apache.commons.lang.StringUtils.isNotBlank(cat.getDescription())) { mCat.setDescription(cat.getDescription()); } openTransaction(); pm.makePersistent(mCat); committed = commitTransaction(); } finally { if (!committed) { rollbackTransaction(); } } }
private MCatalog catToMCat(Catalog cat) { MCatalog mCat = new MCatalog(); mCat.setName(normalizeIdentifier(cat.getName())); if (cat.isSetDescription()) { mCat.setDescription(cat.getDescription()); } mCat.setLocationUri(cat.getLocationUri()); mCat.setCreateTime(cat.getCreateTime()); return mCat; }
@Test public void catalogs() throws MetaException, NoSuchObjectException { final String names[] = {"cat1", "cat2"}; final String locations[] = {"loc1", "loc2"}; final String descriptions[] = {"description 1", "description 2"}; for (int i = 0; i < names.length; i++) { Catalog cat = new CatalogBuilder() .setName(names[i]) .setLocation(locations[i]) .setDescription(descriptions[i]) .build(); objectStore.createCatalog(cat); } List<String> fetchedNames = objectStore.getCatalogs(); Assert.assertEquals(3, fetchedNames.size()); for (int i = 0; i < names.length - 1; i++) { Assert.assertEquals(names[i], fetchedNames.get(i)); Catalog cat = objectStore.getCatalog(fetchedNames.get(i)); Assert.assertEquals(names[i], cat.getName()); Assert.assertEquals(descriptions[i], cat.getDescription()); Assert.assertEquals(locations[i], cat.getLocationUri()); } Catalog cat = objectStore.getCatalog(fetchedNames.get(2)); Assert.assertEquals(DEFAULT_CATALOG_NAME, cat.getName()); Assert.assertEquals(Warehouse.DEFAULT_CATALOG_COMMENT, cat.getDescription()); // Location will vary by system. for (int i = 0; i < names.length; i++) objectStore.dropCatalog(names[i]); fetchedNames = objectStore.getCatalogs(); Assert.assertEquals(1, fetchedNames.size()); }
Assert.assertTrue(catNames[i].equalsIgnoreCase(cat.getName())); Assert.assertEquals(description[i], cat.getDescription()); Assert.assertEquals(location[i], cat.getLocationUri());
public DatabaseBuilder setCatalogName(Catalog catalog) { this.catalogName = catalog.getName(); return this; }
@Override public DropCatalogMessage buildDropCatalogMessage(Catalog catalog) { return new JSONDropCatalogMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, catalog.getName(), now()); }
@Override public CreateCatalogMessage buildCreateCatalogMessage(Catalog catalog) { return new JSONCreateCatalogMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, catalog.getName(), now()); }
@Override public void createCatalog(Catalog cat) throws MetaException { LOG.debug("Creating catalog " + cat.getName()); boolean committed = false; MCatalog mCat = catToMCat(cat); try { openTransaction(); pm.makePersistent(mCat); committed = commitTransaction(); } finally { if (!committed) { rollbackTransaction(); } } }
private MCatalog catToMCat(Catalog cat) { MCatalog mCat = new MCatalog(); mCat.setName(normalizeIdentifier(cat.getName())); if (cat.isSetDescription()) { mCat.setDescription(cat.getDescription()); } mCat.setLocationUri(cat.getLocationUri()); return mCat; }