Search in sources :

Example 46 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class NotificationEntityChangeListenerTest method testGetAllTraitsSuperTraits.

@Test
public void testGetAllTraitsSuperTraits() throws Exception {
    AtlasTypeRegistry typeSystem = mock(AtlasTypeRegistry.class);
    String traitName = "MyTrait";
    Struct myTrait = new Struct(traitName);
    String superTraitName = "MySuperTrait";
    AtlasClassificationType traitDef = mock(AtlasClassificationType.class);
    Set<String> superTypeNames = Collections.singleton(superTraitName);
    AtlasClassificationType superTraitDef = mock(AtlasClassificationType.class);
    Set<String> superSuperTypeNames = Collections.emptySet();
    Referenceable entity = getEntity("id", myTrait);
    when(typeSystem.getClassificationTypeByName(traitName)).thenReturn(traitDef);
    when(typeSystem.getClassificationTypeByName(superTraitName)).thenReturn(superTraitDef);
    when(traitDef.getAllSuperTypes()).thenReturn(superTypeNames);
    when(superTraitDef.getAllSuperTypes()).thenReturn(superSuperTypeNames);
    List<Struct> allTraits = NotificationEntityChangeListener.getAllTraits(entity, typeSystem);
    assertEquals(2, allTraits.size());
    for (Struct trait : allTraits) {
        String typeName = trait.getTypeName();
        assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 47 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class NotificationEntityChangeListenerTest method getEntity.

private Referenceable getEntity(String id, Struct... traits) {
    String typeName = "typeName";
    Map<String, Object> values = new HashMap<>();
    List<String> traitNames = new LinkedList<>();
    Map<String, Struct> traitMap = new HashMap<>();
    for (Struct trait : traits) {
        String traitName = trait.getTypeName();
        traitNames.add(traitName);
        traitMap.put(traitName, trait);
    }
    return new Referenceable(id, typeName, values, traitNames, traitMap);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 48 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class GraphHelper method createVertexWithIdentity.

public AtlasVertex createVertexWithIdentity(Referenceable typedInstance, Set<String> superTypeNames) {
    final String guid = UUID.randomUUID().toString();
    final AtlasVertex vertexWithIdentity = createVertexWithoutIdentity(typedInstance.getTypeName(), new Id(guid, 0, typedInstance.getTypeName()), superTypeNames);
    // add identity
    setProperty(vertexWithIdentity, Constants.GUID_PROPERTY_KEY, guid);
    // add version information
    setProperty(vertexWithIdentity, Constants.VERSION_PROPERTY_KEY, Long.valueOf(typedInstance.getId().getVersion()));
    return vertexWithIdentity;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.v1.model.instance.Id)

Example 49 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class QuickStart method view.

Id view(String name, Id dbId, List<Id> inputTables, String... traitNames) throws AtlasBaseException {
    try {
        Referenceable referenceable = new Referenceable(VIEW_TYPE, traitNames);
        referenceable.set("name", name);
        referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
        referenceable.set("db", dbId);
        referenceable.set(INPUT_TABLES_ATTRIBUTE, inputTables);
        return createInstance(referenceable);
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.QUICK_START, e, String.format("%s Id creation", name));
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasException(org.apache.atlas.AtlasException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 50 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class LineageResource method outputsGraph.

/**
 * Returns the outputs graph for a given entity id.
 *
 * @param guid dataset entity id
 */
@GET
@Path("{guid}/outputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public LineageResponse outputsGraph(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> LineageResource.outputsGraph({})", guid);
    }
    LineageResponse ret = new LineageResponse();
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.outputsGraph(" + guid + ")");
        }
        AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.OUTPUT, -1);
        ret.setRequestId(Servlets.getRequestId());
        ret.setResults(LineageUtils.toLineageStruct(lineageInfo, typeRegistry));
        return ret;
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
        throw e;
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== LineageResource.outputsGraph({})", guid);
        }
    }
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) LineageResponse(org.apache.atlas.v1.model.lineage.LineageResponse) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)62 Test (org.testng.annotations.Test)39 Id (org.apache.atlas.v1.model.instance.Id)38 Struct (org.apache.atlas.v1.model.instance.Struct)15 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)11 List (java.util.List)7 AtlasException (org.apache.atlas.AtlasException)6 AtlasServiceException (org.apache.atlas.AtlasServiceException)6 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)5 HashMap (java.util.HashMap)4 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)4 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)4 Feed (org.apache.falcon.entity.v0.feed.Feed)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3