Java Code Examples for org.apache.atlas.v1.model.instance.Referenceable#getTypeName()

The following examples show how to use org.apache.atlas.v1.model.instance.Referenceable#getTypeName() . 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: AtlasInstanceConverter.java    From atlas with Apache License 2.0 6 votes vote down vote up
public AtlasEntitiesWithExtInfo toAtlasEntities(String[] jsonEntities) throws AtlasBaseException, AtlasException {
    Referenceable[] referenceables = new Referenceable[jsonEntities.length];

    for (int i = 0; i < jsonEntities.length; i++) {
        referenceables[i] = AtlasType.fromV1Json(jsonEntities[i], Referenceable.class);
    }

    AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
    ConverterContext           context   = new ConverterContext();

    for (Referenceable referenceable : referenceables) {
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());

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

        AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, context);

        context.addEntity(entity);
    }

    AtlasEntitiesWithExtInfo ret = context.getEntities();

    return ret;
}
 
Example 2
Source File: AtlasJson.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Referenceable entity, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    if (entity != null) {
        Map<String, Object> valueMap = entity.getValues() != null ? new HashMap<>(entity.getValues()) : new HashMap<>();

        if (entity.getTypeName() != null) {
            valueMap.put(V1_KEY_$TYPENAME, entity.getTypeName());
        }

        if (entity.getId() != null) {
            valueMap.put(V1_KEY_$ID, entity.getId());
        }

        if (entity.getSystemAttributes() != null) {
            valueMap.put(V1_KEY_$SYSTEM_ATTRIBUTES, entity.getSystemAttributes());
        }

        if (MapUtils.isNotEmpty(entity.getTraits())) {
            valueMap.put(V1_KEY_$TRAITS, entity.getTraits());
        }

        jgen.writeObject(valueMap);
    }
}
 
Example 3
Source File: QuickStart.java    From atlas with Apache License 2.0 5 votes vote down vote up
private Id createInstance(Referenceable referenceable) throws Exception {
    String typeName = referenceable.getTypeName();

    String entityJSON = AtlasType.toV1Json(referenceable);
    System.out.println("Submitting new entity= " + entityJSON);
    List<String> guids = metadataServiceClient.createEntity(entityJSON);
    System.out.println("created instance for type " + typeName + ", guid: " + guids);

    // return the Id for created instance with guid
    if (guids.size() > 0) {
        return new Id(guids.get(guids.size() - 1), referenceable.getId().getVersion(), referenceable.getTypeName());
    }

    return null;
}
 
Example 4
Source File: EntityAuditListener.java    From atlas with Apache License 2.0 5 votes vote down vote up
private String getAuditEventDetail(Referenceable entity, EntityAuditAction action) throws AtlasException {
    Map<String, Object> prunedAttributes = pruneEntityAttributesForAudit(entity);

    String auditPrefix  = getV1AuditPrefix(action);
    String auditString  = auditPrefix + AtlasType.toV1Json(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.getId()._getId(), auditSize, auditMaxSize);

        Map<String, Object> attrValues = entity.getValuesMap();

        entity.setValues(null);

        auditString = auditPrefix + AtlasType.toV1Json(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 as well
            LOG.warn("audit record still too long: entityType={}, guid={}, size={}; maxSize={}. audit will have only summary details",
                    entity.getTypeName(), entity.getId()._getId(), auditSize, auditMaxSize);

            Referenceable shallowEntity = new Referenceable(entity.getId(), entity.getTypeName(), null, entity.getSystemAttributes(), null, null);

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

        entity.setValues(attrValues);
    }

    restoreEntityAttributes(entity, prunedAttributes);

    return auditString;
}
 
Example 5
Source File: AtlasInstanceConverter.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasEntitiesWithExtInfo toAtlasEntity(Referenceable referenceable) throws AtlasBaseException {
    AtlasEntityFormatConverter converter  = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
    AtlasEntityType            entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());

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

    ConverterContext ctx    = new ConverterContext();
    AtlasEntity      entity = converter.fromV1ToV2(referenceable, entityType, ctx);

    ctx.addEntity(entity);

    return ctx.getEntities();
}
 
Example 6
Source File: TestNotificationSender.java    From nifi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void assertCreateMessage(Notifier notifier, int notificationIndex, Referenceable ... expects) {
    assertTrue(notifier.notifications.size() > notificationIndex);
    final List<HookNotification> messages = notifier.notifications.get(notificationIndex);
    assertEquals(1, messages.size());
    final HookNotificationV1.EntityCreateRequest message = (HookNotificationV1.EntityCreateRequest) messages.get(0);
    assertEquals(expects.length, message.getEntities().size());

    // The use of 'flatMap' at NotificationSender does not preserve actual entities order.
    // Use typed qname map to assert regardless of ordering.
    final Map<String, Referenceable> entities = message.getEntities().stream().collect(Collectors.toMap(
            ref -> AtlasUtils.toTypedQualifiedName(ref.getTypeName(), (String) ref.get(ATTR_QUALIFIED_NAME)), ref -> ref));

    boolean hasFlowPathSeen = false;
    for (int i = 0; i < expects.length; i++) {
        final Referenceable expect = expects[i];
        final String typeName = expect.getTypeName();
        final Referenceable actual = entities.get(AtlasUtils.toTypedQualifiedName(typeName, (String) expect.get(ATTR_QUALIFIED_NAME)));
        assertNotNull(actual);
        assertEquals(typeName, actual.getTypeName());
        assertEquals(expect.get(ATTR_QUALIFIED_NAME), actual.get(ATTR_QUALIFIED_NAME));

        if (TYPE_NIFI_FLOW_PATH.equals(typeName)) {
            assertIOReferences(expect, actual, ATTR_INPUTS);
            assertIOReferences(expect, actual, ATTR_OUTPUTS);
            hasFlowPathSeen = true;
        } else {
            assertFalse("Types other than nifi_flow_path should be created before any nifi_flow_path entity.", hasFlowPathSeen);
        }
    }
}
 
Example 7
Source File: BaseResourceIT.java    From atlas with Apache License 2.0 4 votes vote down vote up
protected Id createInstance(Referenceable referenceable) throws Exception {
    String typeName = referenceable.getTypeName();

    System.out.println("creating instance of type " + typeName);

    List<String> guids = atlasClientV1.createEntity(referenceable);

    System.out.println("created instance for type " + typeName + ", guid: " + guids);

    // return the reference to created instance with guid
    if (guids.size() > 0) {
        return new Id(guids.get(guids.size() - 1), 0, referenceable.getTypeName());
    }

    return null;
}
 
Example 8
Source File: AtlasAPIV2ServerEmulator.java    From nifi with Apache License 2.0 4 votes vote down vote up
private static AtlasEntity toEntity(Referenceable ref) {
    return new AtlasEntity(ref.getTypeName(), convertReferenceableToObjectId(ref.getValuesMap()));
}