Search in sources :

Example 16 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class EntityGraphRetriever method getClassification.

public AtlasClassification getClassification(String guid, String classificationName) throws AtlasBaseException {
    AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
    if (instanceVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    List<AtlasClassification> classifications = getClassifications(instanceVertex, classificationName);
    if (CollectionUtils.isEmpty(classifications)) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
    }
    return classifications.get(0);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 17 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class EntityGraphRetriever method getClassifications.

private List<AtlasClassification> getClassifications(AtlasVertex instanceVertex, @Nullable String classificationNameFilter) throws AtlasBaseException {
    List<AtlasClassification> classifications = new ArrayList<>();
    List<String> classificationNames = GraphHelper.getTraitNames(instanceVertex);
    if (CollectionUtils.isNotEmpty(classificationNames)) {
        for (String classificationName : classificationNames) {
            AtlasClassification classification;
            if (StringUtils.isNotEmpty(classificationNameFilter)) {
                if (classificationName.equals(classificationNameFilter)) {
                    classification = getClassification(instanceVertex, classificationName);
                    classifications.add(classification);
                    return classifications;
                }
            } else {
                classification = getClassification(instanceVertex, classificationName);
                classifications.add(classification);
            }
        }
        if (StringUtils.isNotEmpty(classificationNameFilter)) {
            //Should not reach here if classification present
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationNameFilter);
        }
    }
    return classifications;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 18 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class EntityGraphMapper method addClassifications.

public void addClassifications(final EntityMutationContext context, String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    if (CollectionUtils.isNotEmpty(classifications)) {
        AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (instanceVertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        String entityTypeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);
        final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
        for (AtlasClassification classification : classifications) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("mapping classification {}", classification);
            }
            GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, classification.getTypeName());
            // add a new AtlasVertex for the struct or trait instance
            AtlasVertex classificationVertex = createClassificationVertex(classification);
            if (LOG.isDebugEnabled()) {
                LOG.debug("created vertex {} for trait {}", string(classificationVertex), classification.getTypeName());
            }
            // add the attributes for the trait instance
            mapClassification(EntityOperation.CREATE, context, classification, entityType, instanceVertex, classificationVertex);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 19 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class EntityGraphRetriever method getClassification.

private AtlasClassification getClassification(AtlasVertex instanceVertex, String classificationName) throws AtlasBaseException {
    AtlasClassification ret = null;
    if (LOG.isDebugEnabled()) {
        LOG.debug("mapping classification {} to atlas entity", classificationName);
    }
    Iterable<AtlasEdge> edges = instanceVertex.getEdges(AtlasEdgeDirection.OUT, classificationName);
    AtlasEdge edge = (edges != null && edges.iterator().hasNext()) ? edges.iterator().next() : null;
    if (edge != null) {
        ret = new AtlasClassification(classificationName);
        mapAttributes(edge.getInVertex(), ret, null);
    }
    return ret;
}
Also used : AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 20 with AtlasClassification

use of org.apache.atlas.model.instance.AtlasClassification in project incubator-atlas by apache.

the class BaseResourceIT method createHiveTableInstanceV2.

protected AtlasEntity createHiveTableInstanceV2(AtlasEntity databaseInstance, String tableName) throws Exception {
    AtlasEntity tableInstance = new AtlasEntity(HIVE_TABLE_TYPE_V2);
    tableInstance.setClassifications(Arrays.asList(new AtlasClassification("classification"), new AtlasClassification("pii"), new AtlasClassification("phi"), new AtlasClassification("pci"), new AtlasClassification("sox"), new AtlasClassification("sec"), new AtlasClassification("finance")));
    tableInstance.setAttribute(NAME, tableName);
    tableInstance.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
    tableInstance.setAttribute("db", AtlasTypeUtil.getAtlasObjectId(databaseInstance));
    tableInstance.setAttribute(DESCRIPTION, "bar table");
    tableInstance.setAttribute("lastAccessTime", "2014-07-11T08:00:00.000Z");
    tableInstance.setAttribute("type", "managed");
    tableInstance.setAttribute("level", 2);
    // enum
    tableInstance.setAttribute("tableType", "MANAGED");
    tableInstance.setAttribute("compressed", false);
    AtlasClassification classification = tableInstance.getClassifications().get(0);
    classification.setAttribute("tag", "foundation_etl");
    AtlasStruct serde1Instance = new AtlasStruct("serdeType");
    serde1Instance.setAttribute(NAME, "serde1");
    serde1Instance.setAttribute("serde", "serde1");
    tableInstance.setAttribute("serde1", serde1Instance);
    AtlasStruct serde2Instance = new AtlasStruct("serdeType");
    serde2Instance.setAttribute(NAME, "serde2");
    serde2Instance.setAttribute("serde", "serde2");
    tableInstance.setAttribute("serde2", serde2Instance);
    List<AtlasClassification> traits = tableInstance.getClassifications();
    Assert.assertEquals(traits.size(), 7);
    return tableInstance;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Aggregations

AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)30 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)4 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 IStruct (org.apache.atlas.typesystem.IStruct)4 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)4 AtlasClassifications (org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications)3 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 HashMap (java.util.HashMap)2 AtlasException (org.apache.atlas.AtlasException)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)2 JSONArray (org.codehaus.jettison.json.JSONArray)2 Map (java.util.Map)1