use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class LineageResource method inputsGraph.
/**
* Returns input lineage graph for the given entity id.
* @param guid dataset entity id
* @return
*/
@GET
@Path("{guid}/inputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public LineageResponse inputsGraph(@PathParam("guid") String guid) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> LineageResource.inputsGraph({})", guid);
}
LineageResponse ret = new LineageResponse();
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.inputsGraph(" + guid + ")");
}
AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.INPUT, -1);
ret.setRequestId(Servlets.getRequestId());
ret.setResults(LineageUtils.toLineageStruct(lineageInfo, typeRegistry));
return ret;
} catch (AtlasBaseException e) {
LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (WebApplicationException e) {
LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e);
throw e;
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== LineageResource.inputsGraph({})", guid);
}
}
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class StormAtlasHook method createTopologyInstance.
private Referenceable createTopologyInstance(TopologyInfo topologyInfo, Map stormConf) {
Referenceable topologyReferenceable = new Referenceable(StormDataTypes.STORM_TOPOLOGY.getName());
topologyReferenceable.set("id", topologyInfo.get_id());
topologyReferenceable.set(AtlasClient.NAME, topologyInfo.get_name());
topologyReferenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, topologyInfo.get_name());
String owner = topologyInfo.get_owner();
if (StringUtils.isEmpty(owner)) {
owner = ANONYMOUS_OWNER;
}
topologyReferenceable.set(AtlasClient.OWNER, owner);
topologyReferenceable.set("startTime", new Date(System.currentTimeMillis()));
topologyReferenceable.set(AtlasConstants.CLUSTER_NAME_ATTRIBUTE, getClusterName(stormConf));
return topologyReferenceable;
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class EntityJerseyResourceIT method testUTF8.
@Test
public void testUTF8() throws Exception {
// Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType()
String classType = randomString();
String attrName = random();
String attrValue = random();
ClassTypeDefinition classTypeDefinition = TypesUtil.createClassTypeDef(classType, null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef(attrName, AtlasBaseTypeDef.ATLAS_TYPE_STRING));
TypesDef typesDef = new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), Collections.<TraitTypeDefinition>emptyList(), Collections.singletonList(classTypeDefinition));
createType(typesDef);
Referenceable instance = new Referenceable(classType);
instance.set(attrName, attrValue);
Id guid = createInstance(instance);
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
Referenceable getReferenceable = AtlasType.fromV1Json(AtlasType.toJson(response.get(AtlasClient.DEFINITION)), Referenceable.class);
Assert.assertEquals(getReferenceable.get(attrName), attrValue);
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class EntityJerseyResourceIT method testAddProperty.
@Test
public void testAddProperty() throws Exception {
String dbName = "db" + randomString();
String tableName = "table" + randomString();
Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
Id dbId = createInstance(hiveDBInstance);
Referenceable referenceable = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
Id id = createInstance(referenceable);
final String guid = id._getId();
try {
Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + guid);
}
// add property
String description = "bar table - new desc";
addProperty(guid, "description", description);
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
Assert.assertNotNull(response);
referenceable.set("description", description);
// invalid property for the type
try {
addProperty(guid, "invalid_property", "bar table");
Assert.fail("Expected AtlasServiceException");
} catch (AtlasServiceException e) {
Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
}
String currentTime = String.valueOf(new DateTime());
// updating date attribute as string not supported in v2
// addProperty(guid, "createTime", currentTime);
response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
Assert.assertNotNull(response);
referenceable.set("createTime", currentTime);
}
use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.
the class EntityJerseyResourceIT method testPartialUpdateByUniqueAttributes.
@Test
public void testPartialUpdateByUniqueAttributes() throws Exception {
String dbName = "db" + randomString();
String tableName = "table" + randomString();
Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
Id dbId = createInstance(hiveDBInstance);
Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
Id tableId = createInstance(hiveTableInstance);
final String guid = tableId._getId();
try {
Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + guid);
}
String colName = "col1" + randomString();
final List<Referenceable> columns = new ArrayList<>();
Map<String, Object> values = new HashMap<>();
values.put(NAME, colName);
values.put("comment", "col1 comment");
values.put(QUALIFIED_NAME, "default.table.col1@" + colName);
values.put("comment", "col1 comment");
values.put("type", "string");
values.put("owner", "user1");
values.put("position", 0);
values.put("description", "col1");
// table is a required reference, can't be null
values.put("table", tableId);
Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
columns.add(ref);
// Update by unique attribute
values.put("type", "int");
ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
columns.set(0, ref);
Referenceable tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {
{
put("columns", columns);
}
});
LOG.debug("Updating entity= {}", tableUpdated);
EntityResult entityResult = atlasClientV1.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, (String) hiveTableInstance.get(QUALIFIED_NAME), tableUpdated);
assertEquals(entityResult.getUpdateEntities().size(), 1);
assertEquals(entityResult.getUpdateEntities().get(0), guid);
Referenceable entity = atlasClientV1.getEntity(guid);
List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
Assert.assertTrue(refs.get(0).getValuesMap().equals(values));
Assert.assertEquals(refs.get(0).get("type"), "int");
}
Aggregations