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);
}
}
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");
}
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);
}
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;
}
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;
}
Aggregations