use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.
the class AlterDatabase method getNotificationMessages.
@Override
public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
AtlasEntitiesWithExtInfo entities = getEntities();
if (entities != null && CollectionUtils.isNotEmpty(entities.getEntities())) {
ret = Collections.singletonList(new EntityUpdateRequestV2(getUserName(), entities));
}
return ret;
}
use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.
the class AlterTable method getNotificationMessages.
@Override
public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = null;
AtlasEntitiesWithExtInfo entities = getEntities();
if (entities != null && CollectionUtils.isNotEmpty(entities.getEntities())) {
ret = Collections.singletonList(new EntityUpdateRequestV2(getUserName(), entities));
}
return ret;
}
use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.
the class AlterTableRename method getNotificationMessages.
@Override
public List<HookNotification> getNotificationMessages() throws Exception {
List<HookNotification> ret = new ArrayList<>();
if (CollectionUtils.isEmpty(getHiveContext().getInputs())) {
LOG.error("AlterTableRename: old-table not found in inputs list");
return ret;
}
Table oldTable = getHiveContext().getInputs().iterator().next().getTable();
Table newTable = null;
if (CollectionUtils.isNotEmpty(getHiveContext().getOutputs())) {
for (WriteEntity entity : getHiveContext().getOutputs()) {
if (entity.getType() == Entity.Type.TABLE) {
newTable = entity.getTable();
// Hive sends with both old and new table names in the outputs which is weird. So skipping that with the below check
if (StringUtils.equalsIgnoreCase(newTable.getDbName(), oldTable.getDbName()) && StringUtils.equalsIgnoreCase(newTable.getTableName(), oldTable.getTableName())) {
newTable = null;
continue;
}
break;
}
}
}
if (newTable == null) {
LOG.error("AlterTableRename: renamed table not found in outputs list");
return ret;
}
AtlasEntityWithExtInfo oldTableEntity = toTableEntity(oldTable);
// first update with oldTable info, so that the table will be created if it is not present in Atlas
ret.add(new EntityUpdateRequestV2(getUserName(), new AtlasEntitiesWithExtInfo(oldTableEntity)));
// update qualifiedName for all columns, partitionKeys, storageDesc
String newTableQualifiedName = getQualifiedName(newTable);
renameColumns((List<AtlasObjectId>) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_COLUMNS), oldTableEntity, newTableQualifiedName, ret);
renameColumns((List<AtlasObjectId>) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_PARTITION_KEYS), oldTableEntity, newTableQualifiedName, ret);
renameStorageDesc((AtlasObjectId) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_STORAGEDESC), oldTableEntity, newTableQualifiedName, ret);
// update qualifiedName and other attributes (like params - which include lastModifiedTime, lastModifiedBy) of the table
AtlasEntityWithExtInfo newTableEntity = toTableEntity(newTable);
// set previous name as the alias
newTableEntity.getEntity().setAttribute(ATTRIBUTE_ALIASES, Collections.singletonList(oldTable.getTableName()));
// remove columns, partitionKeys and storageDesc - as they have already been updated above
removeAttribute(newTableEntity, ATTRIBUTE_COLUMNS);
removeAttribute(newTableEntity, ATTRIBUTE_PARTITION_KEYS);
removeAttribute(newTableEntity, ATTRIBUTE_STORAGEDESC);
AtlasObjectId oldTableId = new AtlasObjectId(oldTableEntity.getEntity().getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME));
ret.add(new EntityPartialUpdateRequestV2(getUserName(), oldTableId, newTableEntity));
context.removeFromKnownTable((String) oldTableEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME));
return ret;
}
use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.
the class AlterTableRenameCol method getNotificationMessages.
@Override
public List<HookNotification> getNotificationMessages() throws Exception {
if (CollectionUtils.isEmpty(getHiveContext().getInputs())) {
LOG.error("AlterTableRenameCol: old-table not found in inputs list");
return null;
}
if (CollectionUtils.isEmpty(getHiveContext().getOutputs())) {
LOG.error("AlterTableRenameCol: new-table not found in outputs list");
return null;
}
List<HookNotification> ret = new ArrayList<>(super.getNotificationMessages());
Table oldTable = getHiveContext().getInputs().iterator().next().getTable();
Table newTable = getHiveContext().getOutputs().iterator().next().getTable();
newTable = getHive().getTable(newTable.getDbName(), newTable.getTableName());
List<FieldSchema> oldColumns = oldTable.getCols();
List<FieldSchema> newColumns = newTable.getCols();
FieldSchema changedColumnOld = null;
FieldSchema changedColumnNew = null;
for (FieldSchema oldColumn : oldColumns) {
if (!newColumns.contains(oldColumn)) {
changedColumnOld = oldColumn;
break;
}
}
for (FieldSchema newColumn : newColumns) {
if (!oldColumns.contains(newColumn)) {
changedColumnNew = newColumn;
break;
}
}
if (changedColumnOld != null && changedColumnNew != null) {
AtlasObjectId oldColumnId = new AtlasObjectId(HIVE_TYPE_COLUMN, ATTRIBUTE_QUALIFIED_NAME, getQualifiedName(oldTable, changedColumnOld));
AtlasEntity newColumn = new AtlasEntity(HIVE_TYPE_COLUMN);
newColumn.setAttribute(ATTRIBUTE_NAME, changedColumnNew.getName());
newColumn.setAttribute(ATTRIBUTE_QUALIFIED_NAME, getQualifiedName(newTable, changedColumnNew));
ret.add(0, new EntityPartialUpdateRequestV2(getUserName(), oldColumnId, new AtlasEntityWithExtInfo(newColumn)));
} else {
LOG.error("AlterTableRenameCol: no renamed column detected");
}
return ret;
}
use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.
the class KafkaConsumerTest method testNextVersionMismatch.
@Test
public void testNextVersionMismatch() throws Exception {
Referenceable entity = getEntity(TRAIT_NAME);
EntityUpdateRequest message = new EntityUpdateRequest("user1", entity);
String json = AtlasType.toV1Json(new AtlasNotificationMessage<>(new MessageVersion("2.0.0"), message));
TopicPartition tp = new TopicPartition("ATLAS_HOOK", 0);
List<ConsumerRecord<String, String>> klist = Collections.singletonList(new ConsumerRecord<>("ATLAS_HOOK", 0, 0L, "mykey", json));
Map mp = Collections.singletonMap(tp, klist);
ConsumerRecords records = new ConsumerRecords(mp);
kafkaConsumer.assign(Collections.singletonList(tp));
when(kafkaConsumer.poll(100L)).thenReturn(records);
AtlasKafkaConsumer consumer = new AtlasKafkaConsumer(NotificationType.HOOK, kafkaConsumer, false, 100L);
try {
List<AtlasKafkaMessage<HookNotification>> messageList = consumer.receive();
assertTrue(messageList.size() > 0);
HookNotification consumedMessage = messageList.get(0).getMessage();
fail("Expected VersionMismatchException!");
} catch (IncompatibleVersionException e) {
e.printStackTrace();
}
}
Aggregations