Tuesday 2 August 2022

Atlas client: add classification to an entity by unique attributes

AtlasClientV2#addClassification() method is used to add classification to an entities by unique attribues.

 

Signature

public void addClassification(ClassificationAssociateRequest request) throws AtlasServiceException

 

Example

ClassificationAssociateRequest classificationAssociateRequest = new ClassificationAssociateRequest();
classificationAssociateRequest.setEntityTypeName("DemoType2");

Map<String, Object> uniqAttributes = new HashMap<>();
uniqAttributes.put("qualifiedName", "AttributeWithListOfStrings_DEMO1");
classificationAssociateRequest.setEntitiesUniqueAttributes(Arrays.asList(uniqAttributes));

AtlasClassification atlasClassification = new AtlasClassification();
atlasClassification.setTypeName("sensitive_data");
atlasClassification.setPropagate(false);

// This is a mandatory attribute for custom classification sensitive_data
atlasClassification.setAttribute("durationInDays", 10);
classificationAssociateRequest.setClassification(atlasClassification);

atlasClient.addClassification(classificationAssociateRequest);

  For example, before running, I do not have any classifications associated with the entity ‘AttributeWithListOfStrings_DEMO1’. After running the application, sensitive_data classification is attached to the entity.


 

Find the below working application.

 

Create atlas-application.properties file under src/main/resources folder.

 

atlas-application.properties

atlas.client.readTimeoutMSecs=30000
atlas.client.connectTimeoutMSecs=30000

Define AddClassificationToAnEntityByUniqueAttribute class.

 

AddClassificationToAnEntityByUniqueAttribute.java

package com.sample.app.classifications;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.ClassificationAssociateRequest;

public class AddClassificationToAnEntityByUniqueAttribute {

    public static void main(String[] args) throws AtlasServiceException {
        AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
                new String[] { "admin", "admin" });

        ClassificationAssociateRequest classificationAssociateRequest = new ClassificationAssociateRequest();
        classificationAssociateRequest.setEntityTypeName("DemoType2");

        Map<String, Object> uniqAttributes = new HashMap<>();
        uniqAttributes.put("qualifiedName", "AttributeWithListOfStrings_DEMO1");
        classificationAssociateRequest.setEntitiesUniqueAttributes(Arrays.asList(uniqAttributes));

        AtlasClassification atlasClassification = new AtlasClassification();
        atlasClassification.setTypeName("sensitive_data");
        atlasClassification.setPropagate(false);

        // This is a mandatory attribute for custom classification sensitive_data
        atlasClassification.setAttribute("durationInDays", 10);
        classificationAssociateRequest.setClassification(atlasClassification);

        atlasClient.addClassification(classificationAssociateRequest);

    }

}

After running above application, I can see that ‘sensitive_data’ classification is attached to the entity.





Previous                                                    Next                                                    Home

No comments:

Post a Comment