Search in sources :

Example 21 with Struct

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;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 22 with Struct

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);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Map(java.util.Map) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 23 with Struct

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);
    }
}
Also used : CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) ResourceAlreadyExistsException(org.apache.atlas.catalog.exception.ResourceAlreadyExistsException) AtlasException(org.apache.atlas.AtlasException) Map(java.util.Map) Struct(org.apache.atlas.typesystem.Struct)

Example 24 with Struct

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;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ArrayList(java.util.ArrayList) Struct(org.apache.atlas.typesystem.Struct)

Example 25 with Struct

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;
}
Also used : LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Struct (org.apache.atlas.typesystem.Struct)56 Test (org.testng.annotations.Test)36 IStruct (org.apache.atlas.typesystem.IStruct)29 Referenceable (org.apache.atlas.typesystem.Referenceable)25 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)17 TraitType (org.apache.atlas.typesystem.types.TraitType)12 ArrayList (java.util.ArrayList)9 LinkedList (java.util.LinkedList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Id (org.apache.atlas.typesystem.persistence.Id)7 JSONObject (org.codehaus.jettison.json.JSONObject)7 BeforeTest (org.testng.annotations.BeforeTest)6 AfterTest (org.testng.annotations.AfterTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 ITypedInstance (org.apache.atlas.typesystem.ITypedInstance)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)4 Date (java.util.Date)3