Search in sources :

Example 16 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class AtlasInstanceConverter method toAtlasEntities.

public AtlasEntity.AtlasEntitiesWithExtInfo toAtlasEntities(List<Referenceable> referenceables) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> toAtlasEntities");
    }
    AtlasFormatConverter.ConverterContext context = new AtlasFormatConverter.ConverterContext();
    for (Referenceable referenceable : referenceables) {
        AtlasEntity entity = fromV1toV2Entity(referenceable, context);
        context.addEntity(entity);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== toAtlasEntities");
    }
    return context.getEntities();
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 17 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class AtlasObjectIdConverter method fromV2ToV1.

@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    Id ret = null;
    if (v2Obj != null) {
        if (v2Obj instanceof Map) {
            Map v2Map = (Map) v2Obj;
            String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
            String typeName = type.getTypeName();
            if (StringUtils.isEmpty(idStr)) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
            }
            ret = new Id(idStr, 0, typeName);
        } else if (v2Obj instanceof AtlasObjectId) {
            // transient-id
            ret = new Id(((AtlasObjectId) v2Obj).getGuid(), 0, type.getTypeName());
        } else if (v2Obj instanceof AtlasEntity) {
            AtlasEntity entity = (AtlasEntity) v2Obj;
            ret = new Id(((AtlasObjectId) v2Obj).getGuid(), 0, type.getTypeName());
        } else {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, type.getTypeCategory().name());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.typesystem.persistence.Id) Map(java.util.Map)

Example 18 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class AtlasObjectIdConverter method fromV1ToV2.

@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, AtlasFormatConverter.ConverterContext converterContext) throws AtlasBaseException {
    Object ret = null;
    if (v1Obj != null) {
        if (v1Obj instanceof Id) {
            Id id = (Id) v1Obj;
            ret = new AtlasObjectId(id._getId(), id.getTypeName());
        } else if (v1Obj instanceof IReferenceableInstance) {
            IReferenceableInstance refInst = (IReferenceableInstance) v1Obj;
            String guid = refInst.getId()._getId();
            ret = new AtlasObjectId(guid, refInst.getTypeName());
            if (!converterContext.entityExists(guid) && hasAnyAssignedAttribute(refInst)) {
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(refInst.getTypeName());
                AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
                AtlasEntity entity = converter.fromV1ToV2(v1Obj, entityType, converterContext);
                converterContext.addReferredEntity(entity);
            }
        }
    }
    return ret;
}
Also used : IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.typesystem.persistence.Id) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 19 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class QuickStartV2 method createEntities.

void createEntities() throws Exception {
    System.out.println("\nCreating sample entities: ");
    // Database entities
    AtlasEntity salesDB = createDatabase(SALES_DB, "sales database", "John ETL", "hdfs://host:8000/apps/warehouse/sales");
    AtlasEntity reportingDB = createDatabase(REPORTING_DB, "reporting database", "Jane BI", "hdfs://host:8000/apps/warehouse/reporting");
    AtlasEntity logDB = createDatabase(LOGGING_DB, "logging database", "Tim ETL", "hdfs://host:8000/apps/warehouse/logging");
    // Storage Descriptor entities
    AtlasEntity storageDesc = createStorageDescriptor("hdfs://host:8000/apps/warehouse/sales", "TextInputFormat", "TextOutputFormat", true);
    // Column entities
    List<AtlasEntity> salesFactColumns = ImmutableList.of(createColumn(TIME_ID_COLUMN, "int", "time id"), createColumn(PRODUCT_ID_COLUMN, "int", "product id"), createColumn(CUSTOMER_ID_COLUMN, "int", "customer id", PII_CLASSIFICATION), createColumn(SALES_COLUMN, "double", "product id", METRIC_CLASSIFICATION));
    List<AtlasEntity> logFactColumns = ImmutableList.of(createColumn(TIME_ID_COLUMN, "int", "time id"), createColumn(APP_ID_COLUMN, "int", "app id"), createColumn(MACHINE_ID_COLUMN, "int", "machine id"), createColumn(LOG_COLUMN, "string", "log data", LOGDATA_CLASSIFICATION));
    List<AtlasEntity> productDimColumns = ImmutableList.of(createColumn(PRODUCT_ID_COLUMN, "int", "product id"), createColumn(PRODUCT_NAME_COLUMN, "string", "product name"), createColumn(BRAND_NAME_COLUMN, "int", "brand name"));
    List<AtlasEntity> timeDimColumns = ImmutableList.of(createColumn(TIME_ID_COLUMN, "int", "time id"), createColumn(DAY_OF_YEAR_COLUMN, "int", "day Of Year"), createColumn(WEEKDAY_COLUMN, "int", "week Day"));
    List<AtlasEntity> customerDimColumns = ImmutableList.of(createColumn(CUSTOMER_ID_COLUMN, "int", "customer id", PII_CLASSIFICATION), createColumn(NAME_COLUMN, "string", "customer name", PII_CLASSIFICATION), createColumn(ADDRESS_COLUMN, "string", "customer address", PII_CLASSIFICATION));
    // Table entities
    AtlasEntity salesFact = createTable(SALES_FACT_TABLE, "sales fact table", salesDB, storageDesc, "Joe", "Managed", salesFactColumns, FACT_CLASSIFICATION);
    AtlasEntity productDim = createTable(PRODUCT_DIM_TABLE, "product dimension table", salesDB, storageDesc, "John Doe", "Managed", productDimColumns, DIMENSION_CLASSIFICATION);
    AtlasEntity customerDim = createTable(CUSTOMER_DIM_TABLE, "customer dimension table", salesDB, storageDesc, "fetl", "External", customerDimColumns, DIMENSION_CLASSIFICATION);
    AtlasEntity timeDim = createTable(TIME_DIM_TABLE, "time dimension table", salesDB, storageDesc, "John Doe", "External", timeDimColumns, DIMENSION_CLASSIFICATION);
    AtlasEntity loggingFactDaily = createTable(LOG_FACT_DAILY_MV_TABLE, "log fact daily materialized view", logDB, storageDesc, "Tim ETL", "Managed", logFactColumns, LOGDATA_CLASSIFICATION);
    AtlasEntity loggingFactMonthly = createTable(LOG_FACT_MONTHLY_MV_TABLE, "logging fact monthly materialized view", logDB, storageDesc, "Tim ETL", "Managed", logFactColumns, LOGDATA_CLASSIFICATION);
    AtlasEntity salesFactDaily = createTable(SALES_FACT_DAILY_MV_TABLE, "sales fact daily materialized view", reportingDB, storageDesc, "Joe BI", "Managed", salesFactColumns, METRIC_CLASSIFICATION);
    AtlasEntity salesFactMonthly = createTable(SALES_FACT_MONTHLY_MV_TABLE, "sales fact monthly materialized view", reportingDB, storageDesc, "Jane BI", "Managed", salesFactColumns, METRIC_CLASSIFICATION);
    // View entities
    createView(PRODUCT_DIM_VIEW, reportingDB, ImmutableList.of(productDim), DIMENSION_CLASSIFICATION, JDBC_CLASSIFICATION);
    createView(CUSTOMER_DIM_VIEW, reportingDB, ImmutableList.of(customerDim), DIMENSION_CLASSIFICATION, JDBC_CLASSIFICATION);
    // Process entities
    createProcess(LOAD_SALES_DAILY_PROCESS, "hive query for daily summary", "John ETL", ImmutableList.of(salesFact, timeDim), ImmutableList.of(salesFactDaily), "create table as select ", "plan", "id", "graph", ETL_CLASSIFICATION);
    createProcess(LOAD_SALES_MONTHLY_PROCESS, "hive query for monthly summary", "John ETL", ImmutableList.of(salesFactDaily), ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph", ETL_CLASSIFICATION);
    createProcess(LOAD_LOGS_MONTHLY_PROCESS, "hive query for monthly summary", "Tim ETL", ImmutableList.of(loggingFactDaily), ImmutableList.of(loggingFactMonthly), "create table as select ", "plan", "id", "graph", ETL_CLASSIFICATION);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 20 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class QuickStartV2 method createDatabase.

AtlasEntity createDatabase(String name, String description, String owner, String locationUri, String... traitNames) throws Exception {
    AtlasEntity entity = new AtlasEntity(DATABASE_TYPE);
    entity.setClassifications(toAtlasClassifications(traitNames));
    entity.setAttribute("name", name);
    entity.setAttribute("description", description);
    entity.setAttribute("owner", owner);
    entity.setAttribute("locationuri", locationUri);
    entity.setAttribute("createTime", System.currentTimeMillis());
    return createInstance(entity, traitNames);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Aggregations

AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)124 Test (org.testng.annotations.Test)58 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)43 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)36 HashMap (java.util.HashMap)25 BeforeTest (org.testng.annotations.BeforeTest)25 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)24 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)24 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)21 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 ArrayList (java.util.ArrayList)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)14 Map (java.util.Map)12 List (java.util.List)11 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)11 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)9 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)9 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)7 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7