Sunday 7 August 2022

Atlas Client: Add one or more classifications to an entity by guid

AtlasClient2#addClassifications method is used to add one or more classifications to an entity by guid.

 

Signature

public void addClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException

For example, I have two classifications ‘classified’ and ‘sensitive_data’ defined in the system.

 


Now, I would like to attach these classifications to the entity ‘AttributeWithSetOfStrings_DEMO1’.  

 


 

As you see above image, the entity ‘AttributeWithSetOfStrings_DEMO1’ do not have any classifications associated with it.

 

Below snippet is used to attach the classifications ("sensitive_data" and  "classified") to the entity.

String entityGuid = "66875fe8-c5f8-40c2-8be0-c24514920b3e";

AtlasClassification sensitiveDataClassification = new AtlasClassification();
sensitiveDataClassification.setTypeName("sensitive_data");
sensitiveDataClassification.setPropagate(false);
// This is a mandatory attribute for custom classification sensitive_data
sensitiveDataClassification.setAttribute("durationInDays", 10);

AtlasClassification classifiedClassification = new AtlasClassification();
classifiedClassification.setTypeName("classified");
classifiedClassification.setPropagate(false);

atlasClient.addClassifications(entityGuid, Arrays.asList(sensitiveDataClassification, classifiedClassification));

 

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 AddClassificationsToAnEntityByGuid class.

 

AddClassificationsToAnEntityByGuid.java

 

package com.sample.app.classifications;

import java.util.Arrays;

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

public class AddClassificationsToAnEntityByGuid {

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

        String entityGuid = "66875fe8-c5f8-40c2-8be0-c24514920b3e";

        AtlasClassification sensitiveDataClassification = new AtlasClassification();
        sensitiveDataClassification.setTypeName("sensitive_data");
        sensitiveDataClassification.setPropagate(false);
        // This is a mandatory attribute for custom classification sensitive_data
        sensitiveDataClassification.setAttribute("durationInDays", 10);

        AtlasClassification classifiedClassification = new AtlasClassification();
        classifiedClassification.setTypeName("classified");
        classifiedClassification.setPropagate(false);

        atlasClient.addClassifications(entityGuid,
                Arrays.asList(sensitiveDataClassification, classifiedClassification));

    }

}

Run above application and you can observe that the classifications are added to the entity.

 


 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment