use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class BaseResourceIT method createHiveTableInstanceBuiltIn.
protected Referenceable createHiveTableInstanceBuiltIn(String dbName, String tableName, Id dbId) throws Exception {
Map<String, Object> values = new HashMap<>();
values.put(NAME, dbName);
values.put(DESCRIPTION, "foo database");
values.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
values.put("owner", "user1");
values.put(CLUSTER_NAME, "cl1");
values.put("parameters", Collections.EMPTY_MAP);
values.put("location", "/tmp");
Referenceable databaseInstance = new Referenceable(dbId._getId(), dbId.getTypeName(), values);
Referenceable tableInstance = new Referenceable(HIVE_TABLE_TYPE_BUILTIN, "classification", "pii", "phi", "pci", "sox", "sec", "finance");
tableInstance.set(NAME, tableName);
tableInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
tableInstance.set("db", databaseInstance);
tableInstance.set(DESCRIPTION, "bar table");
tableInstance.set("lastAccessTime", "2014-07-11T08:00:00.000Z");
tableInstance.set("type", "managed");
tableInstance.set("level", 2);
// enum
tableInstance.set("tableType", 1);
tableInstance.set("compressed", false);
Struct traitInstance = (Struct) tableInstance.getTrait("classification");
traitInstance.set("tag", "foundation_etl");
Struct serde1Instance = new Struct("serdeType");
serde1Instance.set(NAME, "serde1");
serde1Instance.set("serde", "serde1");
tableInstance.set("serde1", serde1Instance);
Struct serde2Instance = new Struct("serdeType");
serde2Instance.set(NAME, "serde2");
serde2Instance.set("serde", "serde2");
tableInstance.set("serde2", serde2Instance);
List<String> traits = tableInstance.getTraits();
Assert.assertEquals(traits.size(), 7);
return tableInstance;
}
use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class DataSetLineageJerseyResourceIT method testOutputsGraphForEntity.
@Test
public void testOutputsGraphForEntity() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject results = atlasClientV1.getOutputGraphForEntity(tableId);
Assert.assertNotNull(results);
Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
Assert.assertEquals(vertices.size(), 3);
Struct vertex = vertices.get(tableId);
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.typesystem.Struct in project incubator-atlas by apache.
the class DefaultTypeSystem method createTraitInstance.
@Override
public void createTraitInstance(String guid, String typeName, Map<String, Object> properties) throws ResourceAlreadyExistsException {
try {
// not using the constructor with properties argument because it is marked 'InterfaceAudience.Private'
Struct struct = new Struct(typeName);
for (Map.Entry<String, Object> propEntry : properties.entrySet()) {
struct.set(propEntry.getKey(), propEntry.getValue());
}
//add Taxonomy Namespace
struct.set(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, TaxonomyResourceProvider.TAXONOMY_NS);
metadataService.addTrait(guid, metadataService.createTraitInstance(struct));
} catch (IllegalArgumentException e) {
//todo: unfortunately, IllegalArgumentException can be thrown for other reasons
if (e.getMessage().contains("is already defined for entity")) {
throw new ResourceAlreadyExistsException(String.format("Tag '%s' already associated with the entity", typeName));
} else {
throw e;
}
} catch (AtlasException e) {
throw new CatalogRuntimeException(String.format("Unable to create trait instance '%s' in type system: %s", typeName, e), e);
}
}
use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class AtlasClient method listTraitDefinitions.
/**
* Get all trait definitions for an entity
* @param guid GUID of the entity
* @return List<String> trait definitions of the traits associated to the entity
* @throws AtlasServiceException
*/
public List<Struct> listTraitDefinitions(final String guid) throws AtlasServiceException {
JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS);
List<JSONObject> traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<JSONObject, JSONObject>());
ArrayList<Struct> traitStructList = new ArrayList<>();
for (JSONObject traitDef : traitDefList) {
Struct traitStruct = InstanceSerialization.fromJsonStruct(traitDef.toString(), true);
traitStructList.add(traitStruct);
}
return traitStructList;
}
use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class NotificationEntityChangeListener method getAllTraits.
// ----- helper methods -------------------------------------------------
// ----- helper methods ----------------------------------------------------
@VisibleForTesting
public static List<IStruct> getAllTraits(IReferenceableInstance entityDefinition, TypeSystem typeSystem) throws AtlasException {
List<IStruct> traitInfo = new LinkedList<>();
for (String traitName : entityDefinition.getTraits()) {
IStruct trait = entityDefinition.getTrait(traitName);
String typeName = trait.getTypeName();
Map<String, Object> valuesMap = trait.getValuesMap();
traitInfo.add(new Struct(typeName, valuesMap));
traitInfo.addAll(getSuperTraits(typeName, valuesMap, typeSystem));
}
return traitInfo;
}
Aggregations