use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class EntityJerseyResourceIT method testAddTraitWithAttribute.
@Test
public void testAddTraitWithAttribute() 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 id = createInstance(hiveTableInstance);
final String guid = id._getId();
try {
Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + guid);
}
final String traitName = "PII_Trait" + randomString();
TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("type", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
createType(typesDef);
Struct traitInstance = new Struct(traitName);
traitInstance.set("type", "SSN");
atlasClientV1.addTrait(guid, traitInstance);
// verify the response
Referenceable entity = atlasClientV1.getEntity(guid);
Assert.assertNotNull(entity);
Assert.assertEquals(entity.getId()._getId(), guid);
assertNotNull(entity.getTrait(traitName));
assertEquals(entity.getTrait(traitName).get("type"), traitInstance.get("type"));
}
use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class EntityJerseyResourceIT method testAddExistingTrait.
@Test
public void testAddExistingTrait() 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 id = createInstance(hiveTableInstance);
final String guid = id._getId();
try {
Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + guid);
}
String traitName = "PII_Trait" + randomString();
TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
createType(typesDef);
Struct traitInstance = new Struct(traitName);
atlasClientV1.addTrait(guid, traitInstance);
try {
atlasClientV1.addTrait(guid, traitInstance);
fail("Duplicate trait addition should've failed");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus(), BAD_REQUEST);
}
}
use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class MetadataDiscoveryJerseyResourceIT method createInstance.
private Id createInstance() throws Exception {
Referenceable entityInstance = new Referenceable("dsl_test_type", "Classification");
entityInstance.set("name", randomString());
entityInstance.set("description", randomString());
Struct traitInstance = (Struct) entityInstance.getTrait("Classification");
tagName = randomString();
traitInstance.set("tag", tagName);
List<String> traits = entityInstance.getTraitNames();
assertEquals(traits.size(), 1);
return createInstance(entityInstance);
}
use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class DataSetLineageJerseyResourceIT method testInputsGraphForEntity.
@Test
public void testInputsGraphForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
ObjectNode results = atlasClientV1.getInputGraphForEntity(tableId);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
resultsInstance.normalize();
Map<String, Object> vertices = (Map<String, Object>) resultsInstance.get("vertices");
Assert.assertEquals(vertices.size(), 4);
Object verticesObject = vertices.get(tableId);
Struct vertex = null;
if (verticesObject instanceof Map) {
vertex = new Struct((Map) verticesObject);
} else if (verticesObject instanceof Struct) {
vertex = (Struct) verticesObject;
}
assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
Assert.assertEquals(edges.size(), 4);
}
use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class DataSetLineageJerseyResourceIT method testOutputsGraph.
@Test
public void testOutputsGraph() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/outputs/graph");
Assert.assertNotNull(response);
System.out.println("outputs graph= " + response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JsonNode results = response.get(AtlasClient.RESULTS);
Assert.assertNotNull(results);
Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
Assert.assertEquals(vertices.size(), 3);
Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
Assert.assertEquals(edges.size(), 4);
}
Aggregations