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));
}
}
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);
}
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;
}
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));
}
}
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);
}
}
}
Aggregations