Search in sources :

Example 1 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class HBaseAtlasHook method notifyAsPrivilegedAction.

private void notifyAsPrivilegedAction(final HBaseOperationContext hbaseOperationContext) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> HBaseAtlasHook.notifyAsPrivilegedAction({})", hbaseOperationContext);
    }
    final List<HookNotification> messages = hbaseOperationContext.getMessages();
    try {
        PrivilegedExceptionAction<Object> privilegedNotify = new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() {
                notifyEntities(messages);
                return hbaseOperationContext;
            }
        };
        // Notify as 'hbase' service user in doAs mode
        UserGroupInformation realUser = hbaseOperationContext.getUgi().getRealUser();
        String numberOfMessages = Integer.toString(messages.size());
        String operation = hbaseOperationContext.getOperation().toString();
        String user = hbaseOperationContext.getUgi().getShortUserName();
        if (realUser != null) {
            LOG.info("Sending notification for event {} as service user {} #messages {}", operation, realUser.getShortUserName(), numberOfMessages);
            realUser.doAs(privilegedNotify);
        } else {
            LOG.info("Sending notification for event {} as service user {} #messages {}", operation, user, numberOfMessages);
            hbaseOperationContext.getUgi().doAs(privilegedNotify);
        }
    } catch (Throwable e) {
        LOG.error("Error during notify {} ", hbaseOperationContext.getOperation(), e);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== HBaseAtlasHook.notifyAsPrivilegedAction()");
    }
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 2 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class CreateTable 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 EntityCreateRequestV2(getUserName(), entities));
    }
    return ret;
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityCreateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2)

Example 3 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class DropDatabase method getNotificationMessages.

@Override
public List<HookNotification> getNotificationMessages() throws Exception {
    List<HookNotification> ret = null;
    List<AtlasObjectId> entities = getEntities();
    if (CollectionUtils.isNotEmpty(entities)) {
        ret = new ArrayList<>(entities.size());
        for (AtlasObjectId entity : entities) {
            ret.add(new EntityDeleteRequestV2(getUserName(), Collections.singletonList(entity)));
        }
    }
    return ret;
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) EntityDeleteRequestV2(org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2)

Example 4 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class SqoopHook method publish.

@Override
public void publish(SqoopJobDataPublisher.Data data) throws AtlasHookException {
    try {
        Configuration atlasProperties = ApplicationProperties.get();
        String clusterName = atlasProperties.getString(ATLAS_CLUSTER_NAME, DEFAULT_CLUSTER_NAME);
        AtlasEntity entDbStore = toSqoopDBStoreEntity(data);
        AtlasEntity entHiveDb = toHiveDatabaseEntity(clusterName, data.getHiveDB());
        AtlasEntity entHiveTable = data.getHiveTable() != null ? toHiveTableEntity(entHiveDb, data.getHiveTable()) : null;
        AtlasEntity entProcess = toSqoopProcessEntity(entDbStore, entHiveDb, entHiveTable, data, clusterName);
        AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo(entProcess);
        entities.addReferredEntity(entDbStore);
        entities.addReferredEntity(entHiveDb);
        if (entHiveTable != null) {
            entities.addReferredEntity(entHiveTable);
        }
        HookNotification message = new EntityCreateRequestV2(AtlasHook.getUser(), entities);
        AtlasHook.notifyEntities(Collections.singletonList(message), atlasProperties.getInt(HOOK_NUM_RETRIES, 3));
    } catch (Exception e) {
        LOG.error("SqoopHook.publish() failed", e);
        throw new AtlasHookException("SqoopHook.publish() failed.", e);
    }
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) Configuration(org.apache.commons.configuration.Configuration) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) ImportException(org.apache.sqoop.util.ImportException) AtlasHookException(org.apache.atlas.hook.AtlasHookException) AtlasHookException(org.apache.atlas.hook.AtlasHookException) EntityCreateRequestV2(org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2)

Example 5 with HookNotification

use of org.apache.atlas.model.notification.HookNotification in project atlas by apache.

the class AtlasHook method notifyEntities.

protected void notifyEntities(String user, List<Referenceable> entities) {
    List<HookNotification> hookNotifications = new ArrayList<>();
    hookNotifications.add(new EntityCreateRequest(user, entities));
    notifyEntities(hookNotifications);
}
Also used : HookNotification(org.apache.atlas.model.notification.HookNotification) ArrayList(java.util.ArrayList) EntityCreateRequest(org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)

Aggregations

HookNotification (org.apache.atlas.model.notification.HookNotification)31 Test (org.testng.annotations.Test)18 ArrayList (java.util.ArrayList)13 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)9 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)9 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)8 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)6 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)6 Map (java.util.Map)5 EntityCreateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV2)5 NotificationException (org.apache.atlas.notification.NotificationException)5 EntityUpdateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityUpdateRequestV2)4 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)3 EntityDeleteRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityDeleteRequestV2)3 EntityPartialUpdateRequestV2 (org.apache.atlas.model.notification.HookNotification.EntityPartialUpdateRequestV2)3 MessageVersion (org.apache.atlas.model.notification.MessageVersion)2 Table (org.apache.hadoop.hive.ql.metadata.Table)2 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)2