Java Code Examples for org.apache.atlas.model.instance.AtlasClassification#setAttribute()

The following examples show how to use org.apache.atlas.model.instance.AtlasClassification#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseResourceIT.java    From atlas with Apache License 2.0 5 votes vote down vote up
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_TAG),
                    new AtlasClassification(PHI_TAG),
                    new AtlasClassification(PCI_TAG),
                    new AtlasClassification(SOX_TAG),
                    new AtlasClassification(SEC_TAG),
                    new AtlasClassification(FINANCE_TAG))
    );

    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);
    tableInstance.setAttribute("tableType", "MANAGED"); // enum
    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;
}
 
Example 2
Source File: BaseResourceIT.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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);
    tableInstance.setAttribute("tableType", "MANAGED"); // enum
    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;
}
 
Example 3
Source File: EntityV2JerseyResourceIT.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testGetTraitNames")
public void testAddTraitWithAttribute() throws Exception {
    final String traitName = "PII_Trait" + randomString();
    AtlasClassificationDef piiTrait = AtlasTypeUtil
            .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
                    AtlasTypeUtil.createRequiredAttrDef("type", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getClassificationDefs().add(piiTrait);
    createType(typesDef);

    AtlasClassification traitInstance = new AtlasClassification(traitName);
    traitInstance.setAttribute("type", "SSN");

    final String guid = createHiveTable().getGuid();
    atlasClientV2.addClassifications(guid, ImmutableList.of(traitInstance));

    // verify the response
    AtlasEntity withAssociationByGuid = atlasClientV2.getEntityByGuid(guid).getEntity();
    assertNotNull(withAssociationByGuid);
    assertFalse(withAssociationByGuid.getClassifications().isEmpty());

    boolean found = false;
    for (AtlasClassification atlasClassification : withAssociationByGuid.getClassifications()) {
        String attribute = (String)atlasClassification.getAttribute("type");
        if (attribute != null && attribute.equals("SSN")) {
            found = true;
            break;
        }
    }
    assertTrue(found);
}
 
Example 4
Source File: ClassificationPropagationTest.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"updatePropagateTagsValue"})
public void addBlockedPropagatedClassifications() throws AtlasBaseException {
    AtlasEntity hdfs_path       = getEntity(HDFS_PATH_EMPLOYEES);
    AtlasEntity employees1      = getEntity(EMPLOYEES1_TABLE);
    AtlasEntity employees2      = getEntity(EMPLOYEES2_TABLE);
    AtlasEntity employees_union = getEntity(EMPLOYEES_UNION_TABLE);

    AtlasClassification PII_tag1 = new AtlasClassification("PII"); PII_tag1.setPropagate(true);
        PII_tag1.setAttribute("type", "from hdfs_path entity");
        PII_tag1.setAttribute("valid", true);

    AtlasClassification PII_tag2 = new AtlasClassification("PII"); PII_tag2.setPropagate(true);
        PII_tag2.setAttribute("type", "from employees1 entity");
        PII_tag2.setAttribute("valid", true);

    AtlasClassification PII_tag3 = new AtlasClassification("PII"); PII_tag3.setPropagate(true);
        PII_tag3.setAttribute("type", "from employees2 entity");
        PII_tag3.setAttribute("valid", true);

    AtlasClassification PII_tag4 = new AtlasClassification("PII"); PII_tag4.setPropagate(true);
        PII_tag4.setAttribute("type", "from employees_union entity");
        PII_tag4.setAttribute("valid", true);

    // add PII to hdfs_path, employees1, employees2 and employee_union
    addClassification(hdfs_path, PII_tag1);
    addClassification(employees1, PII_tag2);
    addClassification(employees2, PII_tag3);

    // check 4 PII tags exists in employee_union table
    assertClassificationExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag1.getTypeName(), hdfs_path.getGuid());
    assertClassificationExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag2.getTypeName(), employees1.getGuid());
    assertClassificationExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag3.getTypeName(), employees2.getGuid());

    AtlasRelationship process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
    Set<AtlasClassification> propagatedClassifications     = process3_employee_union_relationship.getPropagatedClassifications();
    Set<AtlasClassification> blockedClassifications        = process3_employee_union_relationship.getBlockedPropagatedClassifications();

    assertNotNull(propagatedClassifications);
    assertClassificationEquals(propagatedClassifications, PII_tag1);
    assertClassificationEquals(propagatedClassifications, PII_tag2);
    assertClassificationEquals(propagatedClassifications, PII_tag3);
    assertTrue(blockedClassifications.isEmpty());

    // block PII tag propagating from employees1 and employees2
    PII_tag2.setEntityGuid(employees1.getGuid());
    PII_tag3.setEntityGuid(employees2.getGuid());

    process3_employee_union_relationship.setBlockedPropagatedClassifications(new HashSet<>(Arrays.asList(PII_tag2, PII_tag3)));
    relationshipStore.update(process3_employee_union_relationship);

    process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
    propagatedClassifications            = process3_employee_union_relationship.getPropagatedClassifications();
    blockedClassifications               = process3_employee_union_relationship.getBlockedPropagatedClassifications();

    assertClassificationEquals(propagatedClassifications, PII_tag1);
    assertTrue(!blockedClassifications.isEmpty());
    assertClassificationEquals(blockedClassifications, PII_tag2);
    assertClassificationEquals(blockedClassifications, PII_tag3);

    assertClassificationNotExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag2);
    assertClassificationNotExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag3);

    // assert only PII from hdfs_path is propagated to employees_union, PII from employees1 and employees2 is blocked.
    assertEquals(getEntity(EMPLOYEES_UNION_TABLE).getClassifications().size(), 1);
    assertClassificationExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag1.getTypeName(), hdfs_path.getGuid());
}
 
Example 5
Source File: ClassificationPropagationTest.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"addBlockedPropagatedClassifications"})
public void removeBlockedPropagatedClassifications  () throws AtlasBaseException {
    AtlasEntity hdfs_path  = getEntity(HDFS_PATH_EMPLOYEES);
    AtlasEntity employees1 = getEntity(EMPLOYEES1_TABLE);
    AtlasEntity employees2 = getEntity(EMPLOYEES2_TABLE);

    AtlasClassification PII_tag1 = new AtlasClassification("PII"); PII_tag1.setPropagate(true); PII_tag1.setEntityGuid(hdfs_path.getGuid());
        PII_tag1.setAttribute("type", "from hdfs_path entity");
        PII_tag1.setAttribute("valid", true);

    AtlasClassification PII_tag2 = new AtlasClassification("PII"); PII_tag2.setPropagate(true); PII_tag2.setEntityGuid(employees1.getGuid());
        PII_tag2.setAttribute("type", "from employees1 entity");
        PII_tag2.setAttribute("valid", true);

    AtlasClassification PII_tag3 = new AtlasClassification("PII"); PII_tag3.setPropagate(true); PII_tag3.setEntityGuid(employees2.getGuid());
        PII_tag3.setAttribute("type", "from employees2 entity");
        PII_tag3.setAttribute("valid", true);

    AtlasRelationship process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);

    // remove blocked propagated classification entry for PII (from employees2) - allow PII from employees2 to propagate to employee_union
    process3_employee_union_relationship.setBlockedPropagatedClassifications(new HashSet<>(Arrays.asList(PII_tag3)));
    relationshipStore.update(process3_employee_union_relationship);

    process3_employee_union_relationship               = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
    Set<AtlasClassification> propagatedClassifications = process3_employee_union_relationship.getPropagatedClassifications();
    Set<AtlasClassification> blockedClassifications    = process3_employee_union_relationship.getBlockedPropagatedClassifications();

    assertClassificationExistInList(propagatedClassifications, PII_tag1);
    assertClassificationExistInList(propagatedClassifications, PII_tag2);
    assertClassificationExistInList(blockedClassifications, PII_tag3);

    // remove all blocked propagated classification entry
    process3_employee_union_relationship.setBlockedPropagatedClassifications(Collections.emptySet());
    relationshipStore.update(process3_employee_union_relationship);

    process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
    propagatedClassifications            = process3_employee_union_relationship.getPropagatedClassifications();
    blockedClassifications               = process3_employee_union_relationship.getBlockedPropagatedClassifications();

    assertClassificationExistInList(propagatedClassifications, PII_tag1);
    assertClassificationExistInList(propagatedClassifications, PII_tag2);
    assertClassificationExistInList(propagatedClassifications, PII_tag3);
    assertTrue(blockedClassifications.isEmpty());
}
 
Example 6
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
@GraphTransaction
public void updateClassifications(String guid, List<AtlasClassification> newClassifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classifications={} for entity={}", newClassifications, guid);
    }

    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid not specified");
    }

    if (CollectionUtils.isEmpty(newClassifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }

    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    List<AtlasClassification> updatedClassifications = new ArrayList<>();

    for (AtlasClassification newClassification : newClassifications) {
        String              classificationName = newClassification.getTypeName();
        AtlasClassification oldClassification  = getClassification(guid, classificationName);

        if (oldClassification == null) {
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
        }

        validateAndNormalizeForUpdate(newClassification);

        Map<String, Object> newAttrs = newClassification.getAttributes();

        if (MapUtils.isNotEmpty(newAttrs)) {
            for (String attrName : newAttrs.keySet()) {
                oldClassification.setAttribute(attrName, newAttrs.get(attrName));
            }
        }

        entityGraphMapper.updateClassification(new EntityMutationContext(), guid, oldClassification);

        updatedClassifications.add(oldClassification);
    }

    // notify listeners on update to classifications
    entityChangeNotifier.onClassificationUpdatedToEntity(guid, updatedClassifications);
}