@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); } }
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(); }
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case NAME: return isSetName(); case DESCRIPTION: return isSetDescription(); case LOCATION_URI: return isSetLocationUri(); case CREATE_TIME: return isSetCreateTime(); } throw new IllegalStateException(); }
/** * Performs a deep copy on <i>other</i>. */ public Catalog(Catalog other) { __isset_bitfield = other.__isset_bitfield; if (other.isSetName()) { this.name = other.name; } if (other.isSetDescription()) { this.description = other.description; } if (other.isSetLocationUri()) { this.locationUri = other.locationUri; } this.createTime = other.createTime; }
.build(); client.createCatalog(cat); File dir = new File(cat.getLocationUri()); Assert.assertTrue(dir.exists() && dir.isDirectory()); Assert.assertTrue(catNames[i].equalsIgnoreCase(cat.getName())); Assert.assertEquals(description[i], cat.getDescription()); Assert.assertEquals(location[i], cat.getLocationUri()); Assert.assertTrue("Create time of catalog should be set", cat.isSetCreateTime()); Assert.assertTrue("Create time of catalog should be non-zero", cat.getCreateTime() > 0); File dir = new File(cat.getLocationUri()); Assert.assertTrue(dir.exists() && dir.isDirectory()); Assert.assertEquals("file:" + cat.getLocationUri(), db.getLocationUri()); Catalog newCat = new Catalog(client.getCatalog(catNames[0])); String newLocation = MetaStoreTestUtils.getTestWarehouseDir("a_different_location"); newCat.setLocationUri(newLocation); client.alterCatalog(catNames[0], newCat); Catalog fetchedNewCat = client.getCatalog(catNames[0]); Assert.assertEquals(newLocation, fetchedNewCat.getLocationUri()); Assert.assertEquals(description[0], fetchedNewCat.getDescription()); newCat = new Catalog(client.getCatalog(catNames[1])); String newDescription = "an even more descriptive description"; newCat.setDescription(newDescription); client.alterCatalog(catNames[1], newCat); fetchedNewCat = client.getCatalog(catNames[1]); Assert.assertEquals(location[1], fetchedNewCat.getLocationUri());
case NAME: if (value == null) { unsetName(); } else { setName((String)value); unsetDescription(); } else { setDescription((String)value); unsetLocationUri(); } else { setLocationUri((String)value); unsetCreateTime(); } else { setCreateTime((Integer)value);
@Override public void read(org.apache.thrift.protocol.TProtocol prot, GetCatalogResponse struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(1); if (incoming.get(0)) { struct.catalog = new Catalog(); struct.catalog.read(iprot); struct.setCatalogIsSet(true); } } }
@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(); } } }
public Catalog build() throws MetaException { if (name == null) throw new MetaException("You must name the catalog"); if (location == null) throw new MetaException("You must give the catalog a location"); Catalog catalog = new Catalog(name, location); if (description != null) catalog.setDescription(description); return catalog; }
public Catalog deepCopy() { return new Catalog(this); }
throws AlreadyExistsException, InvalidObjectException, MetaException { Catalog catalog = rqst.getCatalog(); startFunction("create_catalog", ": " + catalog.toString()); boolean success = false; Exception ex = null; 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 (catalog.getLocationUri() == null) { throw new InvalidObjectException("You must specify a path for the catalog"); Path catPath = new Path(catalog.getLocationUri()); boolean madeDir = false; Map<String, String> transactionalListenersResponses = Collections.emptyMap(); if (!wh.mkdirs(catPath)) { throw new MetaException("Unable to create catalog path " + catPath + ", failed to create catalog " + catalog.getName()); catalog.setCreateTime((int) time); ms.openTransaction(); ms.createCatalog(catalog);
private Catalog mCatToCat(MCatalog mCat) { Catalog cat = new Catalog(mCat.getName(), mCat.getLocationUri()); if (mCat.getDescription() != null) { cat.setDescription(mCat.getDescription()); } cat.setCreateTime(mCat.getCreateTime()); return cat; }
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(); } }
/** * 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)); } }
throws AlreadyExistsException, InvalidObjectException, MetaException { Catalog catalog = rqst.getCatalog(); startFunction("create_catalog", ": " + catalog.toString()); boolean success = false; Exception ex = null; 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 (catalog.getLocationUri() == null) { throw new InvalidObjectException("You must specify a path for the catalog"); Path catPath = new Path(catalog.getLocationUri()); boolean madeDir = false; Map<String, String> transactionalListenersResponses = Collections.emptyMap(); if (!wh.mkdirs(catPath)) { throw new MetaException("Unable to create catalog path " + catPath + ", failed to create catalog " + catalog.getName()); catalog.getName(), catalog.getLocationUri(), Collections.emptyMap()); db.setCatalogName(catalog.getName()); create_database_core(ms, db);
public void write(org.apache.thrift.protocol.TProtocol oprot, Catalog struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); if (struct.name != null) { oprot.writeFieldBegin(NAME_FIELD_DESC); oprot.writeString(struct.name); oprot.writeFieldEnd(); } if (struct.description != null) { if (struct.isSetDescription()) { oprot.writeFieldBegin(DESCRIPTION_FIELD_DESC); oprot.writeString(struct.description); oprot.writeFieldEnd(); } } if (struct.locationUri != null) { oprot.writeFieldBegin(LOCATION_URI_FIELD_DESC); oprot.writeString(struct.locationUri); oprot.writeFieldEnd(); } if (struct.isSetCreateTime()) { oprot.writeFieldBegin(CREATE_TIME_FIELD_DESC); oprot.writeI32(struct.createTime); oprot.writeFieldEnd(); } oprot.writeFieldStop(); oprot.writeStructEnd(); }
} finally { if (success) { wh.deleteDir(wh.getDnsPath(new Path(cat.getLocationUri())), false, false, false); } else { ms.rollbackTransaction();
if (isSetDescription()) { if (!first) sb.append(", "); sb.append("description:"); if (isSetCreateTime()) { if (!first) sb.append(", "); sb.append("createTime:");
@Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof Catalog) return this.equals((Catalog)that); return false; }