Java Code Examples for org.apache.atlas.model.instance.AtlasEntity#setTypeName()

The following examples show how to use org.apache.atlas.model.instance.AtlasEntity#setTypeName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityGraphRetriever.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private AtlasEntity mapSystemAttributes(AtlasVertex entityVertex, AtlasEntity entity) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Mapping system attributes for type {}", entity.getTypeName());
    }

    entity.setGuid(GraphHelper.getGuid(entityVertex));
    entity.setTypeName(GraphHelper.getTypeName(entityVertex));
    entity.setStatus(GraphHelper.getStatus(entityVertex));
    entity.setVersion(GraphHelper.getVersion(entityVertex).longValue());

    entity.setCreatedBy(GraphHelper.getCreatedByAsString(entityVertex));
    entity.setUpdatedBy(GraphHelper.getModifiedByAsString(entityVertex));

    entity.setCreateTime(new Date(GraphHelper.getCreatedTime(entityVertex)));
    entity.setUpdateTime(new Date(GraphHelper.getModifiedTime(entityVertex)));

    return entity;
}
 
Example 2
Source File: EntityGraphRetriever.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntity mapSystemAttributes(AtlasVertex entityVertex, AtlasEntity entity) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Mapping system attributes for type {}", entity.getTypeName());
    }

    entity.setGuid(getGuid(entityVertex));
    entity.setTypeName(getTypeName(entityVertex));
    entity.setStatus(GraphHelper.getStatus(entityVertex));
    entity.setVersion(GraphHelper.getVersion(entityVertex));

    entity.setCreatedBy(GraphHelper.getCreatedByAsString(entityVertex));
    entity.setUpdatedBy(GraphHelper.getModifiedByAsString(entityVertex));

    entity.setCreateTime(new Date(GraphHelper.getCreatedTime(entityVertex)));
    entity.setUpdateTime(new Date(GraphHelper.getModifiedTime(entityVertex)));

    entity.setHomeId(GraphHelper.getHomeId(entityVertex));

    entity.setIsProxy(GraphHelper.isProxy(entityVertex));
    entity.setIsIncomplete(isEntityIncomplete(entityVertex));

    entity.setProvenanceType(GraphHelper.getProvenanceType(entityVertex));
    entity.setCustomAttributes(getCustomAttributes(entityVertex));
    entity.setLabels(getLabels(entityVertex));

    return entity;
}
 
Example 3
Source File: NiFiAtlasClient.java    From nifi with Apache License 2.0 5 votes vote down vote up
private AtlasEntity registerNiFiFlowEntity(final NiFiFlow nifiFlow) throws AtlasServiceException {
    final List<AtlasEntity> entities = new ArrayList<>();
    final AtlasEntity.AtlasEntitiesWithExtInfo atlasEntities = new AtlasEntity.AtlasEntitiesWithExtInfo(entities);

    if (!nifiFlow.isMetadataUpdated()) {
        // Nothing has been changed, return existing entity.
        return nifiFlow.getExEntity();
    }

    // Create parent flow entity using existing NiFiFlow entity if available, so that common properties are taken over.
    final AtlasEntity flowEntity = nifiFlow.getExEntity() != null ? new AtlasEntity(nifiFlow.getExEntity()) : new AtlasEntity();
    flowEntity.setTypeName(TYPE_NIFI_FLOW);
    flowEntity.setVersion(1L);
    flowEntity.setAttribute(ATTR_NAME, nifiFlow.getFlowName());
    flowEntity.setAttribute(ATTR_QUALIFIED_NAME, nifiFlow.toQualifiedName(nifiFlow.getRootProcessGroupId()));
    flowEntity.setAttribute(ATTR_URL, nifiFlow.getUrl());
    flowEntity.setAttribute(ATTR_DESCRIPTION, nifiFlow.getDescription());

    // If flowEntity is not persisted yet, then store nifi_flow entity to make nifiFlowId available for other entities.
    if (flowEntity.getGuid().startsWith("-")) {
        entities.add(flowEntity);
        final EntityMutationResponse mutationResponse = atlasClient.createEntities(atlasEntities);
        logger.debug("Registered a new nifi_flow entity, mutation response={}", mutationResponse);
        final String assignedNiFiFlowGuid = mutationResponse.getGuidAssignments().get(flowEntity.getGuid());
        flowEntity.setGuid(assignedNiFiFlowGuid);
        nifiFlow.setAtlasGuid(assignedNiFiFlowGuid);
    }

    return flowEntity;
}
 
Example 4
Source File: NiFiFlow.java    From nifi with Apache License 2.0 5 votes vote down vote up
private Tuple<EntityChangeType, AtlasEntity> toAtlasEntity(EntityChangeType changeType, final NiFiFlowPath path) {

        final AtlasEntity entity = EntityChangeType.CREATED.equals(changeType) ? new AtlasEntity() : new AtlasEntity(path.getExEntity());
        entity.setTypeName(TYPE_NIFI_FLOW_PATH);
        entity.setVersion(1L);
        entity.setAttribute(ATTR_NIFI_FLOW, getAtlasObjectId());

        final StringBuilder name = new StringBuilder();
        final StringBuilder description = new StringBuilder();
        path.getProcessComponentIds().forEach(pid -> {
            final String componentName = getProcessComponentName(pid);

            if (name.length() > 0) {
                name.append(", ");
                description.append(", ");
            }
            name.append(componentName);
            description.append(String.format("%s::%s", componentName, pid));
        });

        path.setName(name.toString());
        entity.setAttribute(ATTR_NAME, name.toString());
        entity.setAttribute(ATTR_DESCRIPTION, description.toString());

        // Use first processor's id as qualifiedName.
        entity.setAttribute(ATTR_QUALIFIED_NAME, toQualifiedName(path.getId()));

        entity.setAttribute(ATTR_URL, path.createDeepLinkURL(getUrl()));

        final boolean inputsChanged = setChangedIOIds(path, entity, true);
        final boolean outputsChanged = setChangedIOIds(path, entity, false);

        // Even iff there's no flow path metadata changed, if any IO is changed then the pass should be updated.
        EntityChangeType finalChangeType = EntityChangeType.AS_IS.equals(changeType)
                ? (path.isMetadataUpdated() || inputsChanged || outputsChanged ? EntityChangeType.UPDATED : EntityChangeType.AS_IS)
                : changeType;

        return new Tuple<>(finalChangeType, entity);
    }
 
Example 5
Source File: EntityAuditListenerV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
private String getAuditEventDetail(AtlasEntity entity, EntityAuditActionV2 action) {
    Map<String, Object> prunedAttributes = pruneEntityAttributesForAudit(entity);

    String auditPrefix  = getV2AuditPrefix(action);
    String auditString  = auditPrefix + AtlasType.toJson(entity);
    byte[] auditBytes   = auditString.getBytes(StandardCharsets.UTF_8);
    long   auditSize    = auditBytes != null ? auditBytes.length : 0;
    long   auditMaxSize = auditRepository.repositoryMaxSize();

    if (auditMaxSize >= 0 && auditSize > auditMaxSize) { // don't store attributes in audit
        LOG.warn("audit record too long: entityType={}, guid={}, size={}; maxSize={}. entity attribute values not stored in audit",
                entity.getTypeName(), entity.getGuid(), auditSize, auditMaxSize);

        Map<String, Object> attrValues    = entity.getAttributes();
        Map<String, Object> relAttrValues = entity.getRelationshipAttributes();

        entity.setAttributes(null);
        entity.setRelationshipAttributes(null);

        auditString = auditPrefix + AtlasType.toJson(entity);
        auditBytes  = auditString.getBytes(StandardCharsets.UTF_8); // recheck auditString size
        auditSize   = auditBytes != null ? auditBytes.length : 0;

        if (auditMaxSize >= 0 && auditSize > auditMaxSize) { // don't store classifications and meanings as well
            LOG.warn("audit record still too long: entityType={}, guid={}, size={}; maxSize={}. audit will have only summary details",
                    entity.getTypeName(), entity.getGuid(), auditSize, auditMaxSize);

            AtlasEntity shallowEntity = new AtlasEntity();

            shallowEntity.setGuid(entity.getGuid());
            shallowEntity.setTypeName(entity.getTypeName());
            shallowEntity.setCreateTime(entity.getCreateTime());
            shallowEntity.setUpdateTime(entity.getUpdateTime());
            shallowEntity.setCreatedBy(entity.getCreatedBy());
            shallowEntity.setUpdatedBy(entity.getUpdatedBy());
            shallowEntity.setStatus(entity.getStatus());
            shallowEntity.setVersion(entity.getVersion());

            auditString = auditPrefix + AtlasType.toJson(shallowEntity);
        }

        entity.setAttributes(attrValues);
        entity.setRelationshipAttributes(relAttrValues);
    }

    restoreEntityAttributes(entity, prunedAttributes);

    return auditString;
}