/** * Put a new parameter to the listener event. * * Overridden parameters is not allowed, and an exception may be thrown to avoid a mis-configuration * between listeners setting the same parameters. * * @param name Name of the parameter. * @param value Value of the parameter. * @throws IllegalStateException if a parameter already exists. */ public void putParameter(String name, String value) { putParameterIfAbsent(name, value); updateUnmodifiableParameters(); }
public ListenerEvent(boolean status, IHMSHandler handler) { super(); this.status = status; this.handler = handler; this.parameters = new HashMap<>(PARAMETERS_INITIAL_CAPACITY); updateUnmodifiableParameters(); }
@Override public void onAlterPartition(AlterPartitionEvent ape) throws MetaException { if (ape.getStatus()) { Partition before = ape.getOldPartition(); Partition after = ape.getNewPartition(); String topicName = getTopicName(ape.getTable()); send(messageFactory.buildAlterPartitionMessage(ape.getTable(),before, after, ape.getWriteId()), topicName); } }
@Override public void onDropDatabase(DropDatabaseEvent dbEvent) throws MetaException { // Subscriber can get notification about drop of a database in HCAT // by listening on a topic named "HCAT" and message selector string // as "HCAT_EVENT = HCAT_DROP_DATABASE" if (dbEvent.getStatus()) { String topicName = getTopicPrefix(dbEvent.getIHMSHandler().getConf()); send(messageFactory.buildDropDatabaseMessage(dbEvent.getDatabase()), topicName); } }
@Override public void onDropPartition(DropPartitionEvent partitionEvent) throws MetaException { if (TxnUtils.isTransactionalTable(partitionEvent.getTable())) { txnHandler = getTxnHandler(); txnHandler.cleanupRecords(HiveObjectType.PARTITION, null, partitionEvent.getTable(), partitionEvent.getPartitionIterator()); } }
@Override public void onCreateDatabase(CreateDatabaseEvent dbEvent) throws MetaException { // Subscriber can get notification about addition of a database in HCAT // by listening on a topic named "HCAT" and message selector string // as "HCAT_EVENT = HCAT_ADD_DATABASE" if (dbEvent.getStatus()) { String topicName = getTopicPrefix(dbEvent.getIHMSHandler().getConf()); send(messageFactory.buildCreateDatabaseMessage(dbEvent.getDatabase()), topicName); } }
/** * Listen for an event; if it is a DROP_TABLE event, call export_meta_data * */ @Override public void onEvent(PreEventContext context) throws MetaException, NoSuchObjectException, InvalidOperationException { if (context.getEventType() == PreEventType.DROP_TABLE) { export_meta_data((PreDropTableEvent) context); } }
@Override public void onDropDatabase (DropDatabaseEvent dbEvent) throws MetaException { // We can loop thru all the tables to check if they are ACID first and then perform cleanup, // but it's more efficient to unconditionally perform cleanup for the database, especially // when there are a lot of tables txnHandler = getTxnHandler(); txnHandler.cleanupRecords(HiveObjectType.DATABASE, dbEvent.getDatabase(), null, null); }
@Override public List<Role> list_roles(final String principalName, final PrincipalType principalType) throws TException { incrementCounter("list_roles"); firePreEvent(new PreAuthorizationCallEvent(this)); return getMS().listRoles(principalName, principalType); }
/** * Internal function to notify listeners for meta config change events */ private void notifyMetaListeners(String key, String oldValue, String newValue) throws MetaException { for (MetaStoreEventListener listener : listeners) { listener.onConfigChange(new ConfigChangeEvent(this, key, oldValue, newValue)); } if (transactionalListeners.size() > 0) { // All the fields of this event are final, so no reason to create a new one for each // listener ConfigChangeEvent cce = new ConfigChangeEvent(this, key, oldValue, newValue); for (MetaStoreEventListener transactionalListener : transactionalListeners) { transactionalListener.onConfigChange(cce); } } }
@Override public void onAlterDatabase(AlterDatabaseEvent dbEvent) throws MetaException { Database oldDb = dbEvent.getOldDatabase(); Database newDb = dbEvent.getNewDatabase(); if(!oldDb.getCatalogName().equalsIgnoreCase(newDb.getCatalogName()) || !oldDb.getName().equalsIgnoreCase(newDb.getName())) { txnHandler = getTxnHandler(); txnHandler.onRename( oldDb.getCatalogName(), oldDb.getName(), null, null, newDb.getCatalogName(), newDb.getName(), null, null); } }
@Override public Database get_database(final String name) throws NoSuchObjectException, MetaException { startFunction("get_database", ": " + name); Database db = null; Exception ex = null; try { String[] parsedDbName = parseDbName(name, conf); db = get_database_core(parsedDbName[CAT_NAME], parsedDbName[DB_NAME]); firePreEvent(new PreReadDatabaseEvent(db, this)); } catch (MetaException|NoSuchObjectException e) { ex = e; throw e; } finally { endFunction("get_database", db != null, ex); } return db; }
private void handle(PreAlterTableEvent context) throws MetaException { if (supportedCatalogs.contains(getTableCatalog(context.getNewTable()))) { handleAlterTableTransactionalProp(context); HiveStrictManagedUtils.validateStrictManagedTableWithThrow(getConf(), context.getNewTable()); } }
/** * Listen for an event; if it is a DROP_TABLE event, call export_meta_data * */ @Override public void onEvent(PreEventContext context) throws MetaException, NoSuchObjectException, InvalidOperationException { if (context.getEventType() == PreEventType.DROP_TABLE) { export_meta_data((PreDropTableEvent) context); } }
@Override public List<String> get_role_names() throws TException { incrementCounter("get_role_names"); firePreEvent(new PreAuthorizationCallEvent(this)); List<String> ret; try { ret = getMS().listRoleNames(); return ret; } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Put a new set the parameters to the listener event. * * Overridden parameters is not allowed, and an exception may be thrown to avoid a mis-configuration * between listeners setting the same parameters. * * @param parameters A Map object with the a set of parameters. * @throws IllegalStateException if a parameter already exists. */ public void putParameters(final Map<String, String> parameters) { if (parameters != null) { for (Map.Entry<String, String> entry : parameters.entrySet()) { putParameterIfAbsent(entry.getKey(), entry.getValue()); } updateUnmodifiableParameters(); } }
@Override public void onEvent(PreEventContext context) throws MetaException, NoSuchObjectException, InvalidOperationException { Integer cnt = preEvents.get(context.getEventType()); preEvents.put(context.getEventType(), cnt == null ? 1 : cnt + 1); } }
@Override public void onEvent(PreEventContext context) throws MetaException, NoSuchObjectException, InvalidOperationException { switch (context.getEventType()) { case CREATE_TABLE: handle((PreCreateTableEvent) context); break; case ALTER_TABLE: handle((PreAlterTableEvent) context); break; default: //no validation required.. } }