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

The following examples show how to use org.apache.atlas.model.instance.AtlasEntity#getGuid() . 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: AtlasEntityGraphDiscoveryV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void validateAndNormalizeForUpdate(AtlasEntity entity) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();

    if (! AtlasTypeUtil.isValidGuid(entity.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
    }

    AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
    }

    type.validateValueForUpdate(entity, entity.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
    }

    type.getNormalizedValueForUpdate(entity);
}
 
Example 2
Source File: AtlasEntityGraphDiscoveryV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void validateAndNormalize(AtlasEntity entity) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();

    if (! AtlasTypeUtil.isValidGuid(entity.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
    }

    AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
    }

    type.validateValue(entity, entity.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
    }

    type.getNormalizedValue(entity);
}
 
Example 3
Source File: AtlasUserProfileDTO.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public AtlasEntityWithExtInfo toEntityWithExtInfo(AtlasUserProfile obj) throws AtlasBaseException {
    AtlasEntity            entity            = toEntity(obj);
    AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntityWithExtInfo(entity);

    AtlasObjectId userProfileId = new AtlasObjectId(entity.getGuid(), AtlasUserProfileDTO.ENTITY_TYPE_NAME,
                                                    Collections.singletonMap(AtlasUserProfileDTO.PROPERTY_USER_NAME, obj.getName()));

    List<AtlasObjectId> objectIds = new ArrayList<>();

    for (AtlasUserSavedSearch ss : obj.getSavedSearches()) {
        AtlasEntity ssEntity = savedSearchDTO.toEntity(ss);

        ssEntity.setAttribute(AtlasSavedSearchDTO.PROPERTY_USER_PROFILE, userProfileId);

        entityWithExtInfo.addReferredEntity(ssEntity);

        objectIds.add(new AtlasObjectId(ssEntity.getGuid(), savedSearchDTO.getEntityType().getTypeName(), savedSearchDTO.getUniqueAttributes(ss)));
    }

    if (objectIds.size() > 0) {
        entity.setAttribute(PROPERTY_SAVED_SEARCHES, objectIds);
    }

    return entityWithExtInfo;
}
 
Example 4
Source File: AtlasEntityGraphDiscoveryV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void validateAndNormalize(AtlasEntity entity) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();

    if (!AtlasTypeUtil.isValidGuid(entity.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
    }

    AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
    }

    validateCustomAttributes(entity);

    validateLabels(entity.getLabels());

    type.validateValue(entity, entity.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
    }

    type.getNormalizedValue(entity);
}
 
Example 5
Source File: AtlasEntityGraphDiscoveryV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void validateAndNormalizeForUpdate(AtlasEntity entity) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();

    if (!AtlasTypeUtil.isValidGuid(entity.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
    }

    AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
    }

    validateCustomAttributes(entity);

    validateLabels(entity.getLabels());

    type.validateValueForUpdate(entity, entity.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
    }

    type.getNormalizedValueForUpdate(entity);
}
 
Example 6
Source File: EntityAuditListenerV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void onClassificationsUpdated(AtlasEntity entity, List<AtlasClassification> classifications) throws AtlasBaseException {
    if (CollectionUtils.isNotEmpty(classifications)) {
        MetricRecorder metric = RequestContext.get().startMetricRecord("entityAudit");

        List<EntityAuditEventV2> events = new ArrayList<>();
        String                   guid   = entity.getGuid();

        for (AtlasClassification classification : classifications) {
            if (guid.equals(classification.getEntityGuid())) {
                events.add(createEvent(entity, CLASSIFICATION_UPDATE, "Updated classification: " + AtlasType.toJson(classification)));
            } else {
                if (isPropagatedClassificationAdded(guid, classification)) {
                    events.add(createEvent(entity, PROPAGATED_CLASSIFICATION_ADD, "Added propagated classification: " + AtlasType.toJson(classification)));
                } else if (isPropagatedClassificationDeleted(guid, classification)) {
                    events.add(createEvent(entity, PROPAGATED_CLASSIFICATION_DELETE, "Deleted propagated classification: " + classification.getTypeName()));
                } else {
                    events.add(createEvent(entity, PROPAGATED_CLASSIFICATION_UPDATE, "Updated propagated classification: " + AtlasType.toJson(classification)));
                }
            }
        }

        auditRepository.putEventsV2(events);

        RequestContext.get().endMetricRecord(metric);
    }
}
 
Example 7
Source File: QuickStartV2.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private String getTableId(String tableName) throws AtlasServiceException {
    Map<String, String> attributes = new HashMap<>();
    attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);

    AtlasEntity tableEntity = atlasClientV2.getEntityByAttribute(TABLE_TYPE, attributes).getEntity();
    return tableEntity.getGuid();
}
 
Example 8
Source File: BulkImporterImpl.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static void updateVertexGuid(AtlasGraph atlasGraph, AtlasTypeRegistry typeRegistry, EntityGraphRetriever entityGraphRetriever, AtlasEntity entity) {
    String entityGuid = entity.getGuid();
    AtlasObjectId objectId = entityGraphRetriever.toAtlasObjectIdWithoutGuid(entity);

    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
    String vertexGuid = null;
    try {
        vertexGuid = AtlasGraphUtilsV2.getGuidByUniqueAttributes(atlasGraph, entityType, objectId.getUniqueAttributes());
    } catch (AtlasBaseException e) {
        LOG.warn("Entity: {}: Does not exist!", objectId);
        return;
    }

    if (StringUtils.isEmpty(vertexGuid) || vertexGuid.equals(entityGuid)) {
        return;
    }

    AtlasVertex v = AtlasGraphUtilsV2.findByGuid(atlasGraph, vertexGuid);
    if (v == null) {
        return;
    }

    addHistoricalGuid(v, vertexGuid);
    AtlasGraphUtilsV2.setProperty(v, Constants.GUID_PROPERTY_KEY, entityGuid);

    LOG.warn("GUID Updated: Entity: {}: from: {}: to: {}", objectId, vertexGuid, entity.getGuid());
}
 
Example 9
Source File: HiveMetastoreHookIT.java    From atlas with Apache License 2.0 5 votes vote down vote up
private String getColumnId(AtlasEntityWithExtInfo entityWithExtInfo, String columnName) {
    String ret = null;

    for (AtlasEntity entity : entityWithExtInfo.getReferredEntities().values()) {

        if (entity.getTypeName().equals("hive_column") && entity.getAttribute("name").equals(columnName)) {
            ret = entity.getGuid();
            break;
        }
    }

    return ret;
}
 
Example 10
Source File: BaseImpalaEvent.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasObjectId getObjectId(AtlasEntity entity) {
    String        qualifiedName = (String) entity.getAttribute(ATTRIBUTE_QUALIFIED_NAME);
    AtlasObjectId ret           = new AtlasObjectId(entity.getGuid(), entity.getTypeName(), Collections
        .singletonMap(ATTRIBUTE_QUALIFIED_NAME, qualifiedName));

    return ret;
}
 
Example 11
Source File: AtlasTypeUtil.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasObjectId getAtlasObjectId(AtlasEntity entity) {
    return new AtlasObjectId(entity.getGuid(), entity.getTypeName());
}
 
Example 12
Source File: RequestContext.java    From atlas with Apache License 2.0 4 votes vote down vote up
public void cache(AtlasEntity entity) {
    if (entity != null && entity.getGuid() != null) {
        entityCache.put(entity.getGuid(), entity);
    }
}
 
Example 13
Source File: TestUtilsV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static Map<String, AtlasEntity> createDeptEg1() {
    Map<String, AtlasEntity> deptEmpEntities = new HashMap<>();

    AtlasEntity hrDept = new AtlasEntity(DEPARTMENT_TYPE);
    AtlasEntity john = new AtlasEntity(EMPLOYEE_TYPE);

    AtlasEntity jane = new AtlasEntity("Manager");
    AtlasEntity johnAddr = new AtlasEntity("Address");
    AtlasEntity janeAddr = new AtlasEntity("Address");
    AtlasEntity julius = new AtlasEntity("Manager");
    AtlasEntity juliusAddr = new AtlasEntity("Address");
    AtlasEntity max = new AtlasEntity(EMPLOYEE_TYPE);
    AtlasEntity maxAddr = new AtlasEntity("Address");

    AtlasObjectId deptId = new AtlasObjectId(hrDept.getGuid(), hrDept.getTypeName());
    hrDept.setAttribute("name", "hr");
    john.setAttribute("name", "John");
    john.setAttribute("department", deptId);
    johnAddr.setAttribute("street", "Stewart Drive");
    johnAddr.setAttribute("city", "Sunnyvale");
    john.setAttribute("address", johnAddr);

    john.setAttribute("birthday",new Date(1950, 5, 15));
    john.setAttribute("hasPets", true);
    john.setAttribute("numberOfCars", 1);
    john.setAttribute("houseNumber", 153);
    john.setAttribute("carMileage", 13364);
    john.setAttribute("shares", 15000);
    john.setAttribute("salary", 123345.678);
    john.setAttribute("age", 50);
    john.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000"));
    john.setAttribute("approximationOfPi", new BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286"));

    jane.setAttribute("name", "Jane");
    jane.setAttribute("department", deptId);
    janeAddr.setAttribute("street", "Great America Parkway");
    janeAddr.setAttribute("city", "Santa Clara");
    jane.setAttribute("address", janeAddr);
    janeAddr.setAttribute("street", "Great America Parkway");

    julius.setAttribute("name", "Julius");
    julius.setAttribute("department", deptId);
    juliusAddr.setAttribute("street", "Madison Ave");
    juliusAddr.setAttribute("city", "Newtonville");
    julius.setAttribute("address", juliusAddr);
    julius.setAttribute("subordinates", Collections.emptyList());

    AtlasObjectId janeId = getAtlasObjectId(jane);
    AtlasObjectId johnId = getAtlasObjectId(john);

    //TODO - Change to MANAGER_TYPE for JULIUS
    AtlasObjectId maxId = new AtlasObjectId(max.getGuid(), EMPLOYEE_TYPE);
    AtlasObjectId juliusId = new AtlasObjectId(julius.getGuid(), EMPLOYEE_TYPE);

    max.setAttribute("name", "Max");
    max.setAttribute("department", deptId);
    maxAddr.setAttribute("street", "Ripley St");
    maxAddr.setAttribute("city", "Newton");
    max.setAttribute("address", maxAddr);
    max.setAttribute("manager", janeId);
    max.setAttribute("mentor", juliusId);
    max.setAttribute("birthday",new Date(1979, 3, 15));
    max.setAttribute("hasPets", true);
    max.setAttribute("age", 36);
    max.setAttribute("numberOfCars", 2);
    max.setAttribute("houseNumber", 17);
    max.setAttribute("carMileage", 13);
    max.setAttribute("shares", Long.MAX_VALUE);
    max.setAttribute("salary", Double.MAX_VALUE);
    max.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000000000000"));
    max.setAttribute("approximationOfPi", new BigDecimal("3.1415926535897932"));

    john.setAttribute("manager", janeId);
    john.setAttribute("mentor", maxId);
    hrDept.setAttribute("employees", Arrays.asList(johnId, janeId, juliusId, maxId));

    jane.setAttribute("subordinates", Arrays.asList(johnId, maxId));

    deptEmpEntities.put(jane.getGuid(), jane);
    deptEmpEntities.put(john.getGuid(), john);
    deptEmpEntities.put(julius.getGuid(), julius);
    deptEmpEntities.put(max.getGuid(), max);
    deptEmpEntities.put(deptId.getGuid(), hrDept);
    return deptEmpEntities;
}
 
Example 14
Source File: AtlasTypeUtil.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasObjectId getObjectId(AtlasEntity entity) {
    String qualifiedName = (String) entity.getAttribute(ATTRIBUTE_QUALIFIED_NAME);
    AtlasObjectId ret = new AtlasObjectId(entity.getGuid(), entity.getTypeName(), Collections.singletonMap(ATTRIBUTE_QUALIFIED_NAME, qualifiedName));

    return ret;
}
 
Example 15
Source File: NiFiFlowPath.java    From nifi with Apache License 2.0 4 votes vote down vote up
public void setExEntity(AtlasEntity exEntity) {
    this.exEntity = exEntity;
    this.atlasGuid = exEntity.getGuid();
}
 
Example 16
Source File: QuickStartV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
private String getTableId(String tableName) throws AtlasServiceException {
    Map<String, String> attributes  = Collections.singletonMap(REFERENCEABLE_ATTRIBUTE_NAME, tableName + CLUSTER_SUFFIX);
    AtlasEntity         tableEntity = atlasClientV2.getEntityByAttribute(TABLE_TYPE, attributes).getEntity();

    return tableEntity.getGuid();
}
 
Example 17
Source File: TestUtilsV2.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static Map<String, AtlasEntity> createDeptEg1() {
    Map<String, AtlasEntity> deptEmpEntities = new HashMap<>();

    AtlasEntity hrDept = new AtlasEntity(DEPARTMENT_TYPE);
    AtlasEntity john = new AtlasEntity(EMPLOYEE_TYPE);

    AtlasEntity jane = new AtlasEntity("Manager");
    AtlasEntity johnAddr = new AtlasEntity("Address");
    AtlasEntity janeAddr = new AtlasEntity("Address");
    AtlasEntity julius = new AtlasEntity("Manager");
    AtlasEntity juliusAddr = new AtlasEntity("Address");
    AtlasEntity max = new AtlasEntity(EMPLOYEE_TYPE);
    AtlasEntity maxAddr = new AtlasEntity("Address");

    AtlasObjectId deptId = new AtlasObjectId(hrDept.getGuid(), hrDept.getTypeName());
    hrDept.setAttribute("name", "hr");
    john.setAttribute("name", "John");
    john.setAttribute("department", deptId);
    johnAddr.setAttribute("street", "Stewart Drive");
    johnAddr.setAttribute("city", "Sunnyvale");
    john.setAttribute("address", johnAddr);

    john.setAttribute("birthday",new Date(1950, 5, 15));
    john.setAttribute("hasPets", true);
    john.setAttribute("numberOfCars", 1);
    john.setAttribute("houseNumber", 153);
    john.setAttribute("carMileage", 13364);
    john.setAttribute("shares", 15000);
    john.setAttribute("salary", 123345.678);
    john.setAttribute("age", 50);
    john.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000"));
    john.setAttribute("approximationOfPi", new BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286"));

    jane.setAttribute("name", "Jane");
    jane.setAttribute("department", deptId);
    janeAddr.setAttribute("street", "Great America Parkway");
    janeAddr.setAttribute("city", "Santa Clara");
    jane.setAttribute("address", janeAddr);
    janeAddr.setAttribute("street", "Great America Parkway");

    julius.setAttribute("name", "Julius");
    julius.setAttribute("department", deptId);
    juliusAddr.setAttribute("street", "Madison Ave");
    juliusAddr.setAttribute("city", "Newtonville");
    julius.setAttribute("address", juliusAddr);
    julius.setAttribute("subordinates", ImmutableList.of());

    AtlasObjectId janeId = AtlasTypeUtil.getAtlasObjectId(jane);
    AtlasObjectId johnId = AtlasTypeUtil.getAtlasObjectId(john);

    //TODO - Change to MANAGER_TYPE for JULIUS
    AtlasObjectId maxId = new AtlasObjectId(max.getGuid(), EMPLOYEE_TYPE);
    AtlasObjectId juliusId = new AtlasObjectId(julius.getGuid(), EMPLOYEE_TYPE);

    max.setAttribute("name", "Max");
    max.setAttribute("department", deptId);
    maxAddr.setAttribute("street", "Ripley St");
    maxAddr.setAttribute("city", "Newton");
    max.setAttribute("address", maxAddr);
    max.setAttribute("manager", janeId);
    max.setAttribute("mentor", juliusId);
    max.setAttribute("birthday",new Date(1979, 3, 15));
    max.setAttribute("hasPets", true);
    max.setAttribute("age", 36);
    max.setAttribute("numberOfCars", 2);
    max.setAttribute("houseNumber", 17);
    max.setAttribute("carMileage", 13);
    max.setAttribute("shares", Long.MAX_VALUE);
    max.setAttribute("salary", Double.MAX_VALUE);
    max.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000000000000"));
    max.setAttribute("approximationOfPi", new BigDecimal("3.1415926535897932"));

    john.setAttribute("manager", janeId);
    john.setAttribute("mentor", maxId);
    hrDept.setAttribute("employees", ImmutableList.of(johnId, janeId, juliusId, maxId));

    jane.setAttribute("subordinates", ImmutableList.of(johnId, maxId));

    deptEmpEntities.put(jane.getGuid(), jane);
    deptEmpEntities.put(john.getGuid(), john);
    deptEmpEntities.put(julius.getGuid(), julius);
    deptEmpEntities.put(max.getGuid(), max);
    deptEmpEntities.put(deptId.getGuid(), hrDept);
    return deptEmpEntities;
}
 
Example 18
Source File: AtlasTypeUtil.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasObjectId getAtlasObjectId(AtlasEntity entity) {
    return new AtlasObjectId(entity.getGuid(), entity.getTypeName());
}
 
Example 19
Source File: EntityAuditListenerV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
private EntityAuditEventV2 createEvent(AtlasEntity entity, EntityAuditActionV2 action, String details) {
    return new EntityAuditEventV2(entity.getGuid(), RequestContext.get().getRequestTime(),
                                  RequestContext.get().getUser(), action, details, entity);
}
 
Example 20
Source File: EntityNotificationListenerV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
private AtlasEntityHeader toNotificationHeader(AtlasEntity entity) {
    AtlasEntityHeader ret         = new AtlasEntityHeader(entity.getTypeName(), entity.getGuid(), new HashMap<>());
    Object            name        = entity.getAttribute(NAME);
    Object            displayText = name != null ? name : entity.getAttribute(QUALIFIED_NAME);

    ret.setGuid(entity.getGuid());
    ret.setStatus(entity.getStatus());
    ret.setIsIncomplete(entity.getIsIncomplete());

    setAttribute(ret, NAME, name);
    setAttribute(ret, DESCRIPTION, entity.getAttribute(DESCRIPTION));
    setAttribute(ret, OWNER, entity.getAttribute(OWNER));
    setAttribute(ret, CREATE_TIME, entity.getAttribute(CREATE_TIME));

    if (displayText != null) {
        ret.setDisplayText(displayText.toString());
    }

    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());

    if (entityType != null) {
        for (AtlasAttribute attribute : entityType.getAllAttributes().values()) {
            if (attribute.getAttributeDef().getIsUnique() || attribute.getAttributeDef().getIncludeInNotification()) {
                Object attrValue = entity.getAttribute(attribute.getName());

                if (attrValue != null) {
                    ret.setAttribute(attribute.getName(), attrValue);
                }
            }
        }

        if (CollectionUtils.isNotEmpty(entity.getClassifications())) {
            List<AtlasClassification> classifications     = new ArrayList<>(entity.getClassifications().size());
            List<String>              classificationNames = new ArrayList<>(entity.getClassifications().size());

            for (AtlasClassification classification : getAllClassifications(entity.getClassifications())) {
                classifications.add(classification);
                classificationNames.add(classification.getTypeName());
            }

            ret.setClassifications(classifications);
            ret.setClassificationNames(classificationNames);
        }
    }

    return ret;
}