Search in sources :

Example 76 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testDeleteEntityByUniqAttribute.

@Test
public void testDeleteEntityByUniqAttribute() throws Exception {
    // Create database entity
    Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName = randomString();
    db1.set(NAME, dbName);
    db1.set(QUALIFIED_NAME, dbName);
    db1.set(CLUSTER_NAME, randomString());
    db1.set(DESCRIPTION, randomString());
    db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    db1.set("owner", "user1");
    db1.set(CLUSTER_NAME, "cl1");
    db1.set("parameters", Collections.EMPTY_MAP);
    db1.set("location", "/tmp");
    Id db1Id = createInstance(db1);
    // Delete the database entity
    List<String> deletedGuidsList = atlasClientV1.deleteEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, dbName).getDeletedEntities();
    // Verify that deleteEntities() response has database entity guids
    Assert.assertEquals(deletedGuidsList.size(), 1);
    Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
    // Verify entities were deleted from the repository.
    for (String guid : deletedGuidsList) {
        Referenceable entity = atlasClientV1.getEntity(guid);
        assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 77 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityLineageJerseyResourceIT method setupInstances.

private void setupInstances() throws Exception {
    salesDBName = "Sales" + randomString();
    Id salesDB = database(salesDBName, "Sales Database", "John ETL", "hdfs://host:8000/apps/warehouse/sales");
    List<Referenceable> salesFactColumns = ImmutableList.of(column("time_id", "int", "time id"), column("product_id", "int", "product id"), column("customer_id", "int", "customer id"), column("sales", "double", "product id"));
    salesFactTable = "sales_fact" + randomString();
    Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns);
    List<Referenceable> timeDimColumns = ImmutableList.of(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"), column("weekDay", "int", "week Day"));
    Id timeDim = table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL", timeDimColumns);
    Id reportingDB = database("Reporting" + randomString(), "reporting database", "Jane BI", "hdfs://host:8000/apps/warehouse/reporting");
    Id salesFactDaily = table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB, "Joe BI", "MANAGED", salesFactColumns);
    loadProcess("loadSalesDaily" + randomString(), "John ETL", ImmutableList.of(salesFact, timeDim), ImmutableList.of(salesFactDaily), "create table as select ", "plan", "id", "graph");
    salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
    Id salesFactMonthly = table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI", "MANAGED", salesFactColumns);
    loadProcess("loadSalesMonthly" + randomString(), "John ETL", ImmutableList.of(salesFactDaily), ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph");
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id)

Example 78 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class DefaultMetadataService method deleteEntityByUniqueAttribute.

@Override
public EntityResult deleteEntityByUniqueAttribute(String typeName, String uniqueAttributeName, String attrValue) throws AtlasException {
    typeName = ParamChecker.notEmpty(typeName, "delete candidate typeName");
    uniqueAttributeName = ParamChecker.notEmpty(uniqueAttributeName, "delete candidate unique attribute name");
    attrValue = ParamChecker.notEmpty(attrValue, "delete candidate unique attribute value");
    //Throws EntityNotFoundException if the entity could not be found by its unique attribute
    ITypedReferenceableInstance instance = getEntityDefinitionReference(typeName, uniqueAttributeName, attrValue);
    final Id instanceId = instance.getId();
    List<String> deleteCandidateGuids = new ArrayList<String>() {

        {
            add(instanceId._getId());
        }
    };
    return deleteGuids(deleteCandidateGuids);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) Id(org.apache.atlas.typesystem.persistence.Id)

Example 79 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class DefaultMetadataService method validateAndConvertToTypedInstance.

@Override
public ITypedReferenceableInstance validateAndConvertToTypedInstance(IReferenceableInstance updatedEntity, String typeName) throws AtlasException {
    ClassType type = typeSystem.getDataType(ClassType.class, typeName);
    ITypedReferenceableInstance newInstance = type.createInstance(updatedEntity.getId());
    for (String attributeName : updatedEntity.getValuesMap().keySet()) {
        AttributeInfo attributeInfo = type.fieldMapping.fields.get(attributeName);
        if (attributeInfo == null) {
            throw new AtlasException("Invalid property " + attributeName + " for entity " + updatedEntity);
        }
        DataTypes.TypeCategory attrTypeCategory = attributeInfo.dataType().getTypeCategory();
        Object value = updatedEntity.get(attributeName);
        switch(attrTypeCategory) {
            case CLASS:
                if (value != null) {
                    if (value instanceof Referenceable) {
                        newInstance.set(attributeName, value);
                    } else {
                        Id id = new Id((String) value, 0, attributeInfo.dataType().getName());
                        newInstance.set(attributeName, id);
                    }
                }
                break;
            case ENUM:
            case PRIMITIVE:
            case ARRAY:
            case STRUCT:
            case MAP:
                newInstance.set(attributeName, value);
                break;
            case TRAIT:
            //TODO - handle trait updates as well?
            default:
                throw new AtlasException("Update of " + attrTypeCategory + " is not supported");
        }
    }
    return newInstance;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) JSONObject(org.codehaus.jettison.json.JSONObject) Id(org.apache.atlas.typesystem.persistence.Id) AtlasException(org.apache.atlas.AtlasException)

Example 80 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class TestUtils method createTableEntity.

public static Referenceable createTableEntity(String dbId) {
    Referenceable entity = new Referenceable(TABLE_TYPE);
    String tableName = RandomStringUtils.randomAlphanumeric(10);
    entity.set(NAME, tableName);
    entity.set("description", "random table");
    entity.set("type", "type");
    entity.set("tableType", "MANAGED");
    entity.set("database", new Id(dbId, 0, DATABASE_TYPE));
    entity.set("created", new Date());
    return entity;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) Date(java.util.Date)

Aggregations

Id (org.apache.atlas.typesystem.persistence.Id)94 Referenceable (org.apache.atlas.typesystem.Referenceable)50 Test (org.testng.annotations.Test)37 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)28 List (java.util.List)17 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)12 ImmutableList (com.google.common.collect.ImmutableList)10 TraitType (org.apache.atlas.typesystem.types.TraitType)10 JSONObject (org.codehaus.jettison.json.JSONObject)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 Struct (org.apache.atlas.typesystem.Struct)7 ClassType (org.apache.atlas.typesystem.types.ClassType)7 AtlasException (org.apache.atlas.AtlasException)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5