org.apache.atlas.type.AtlasTypeRegistry Java Examples

The following examples show how to use org.apache.atlas.type.AtlasTypeRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityAttribute.java    From atlas with Apache License 2.0 6 votes vote down vote up
public EntityAttribute(String attributeKey, TransformerContext context) {
    this.attributeKey = attributeKey;

    int idx = attributeKey != null ? attributeKey.indexOf(TYPE_NAME_ATTRIBUTE_NAME_SEP) : -1;

    if (idx != -1) {
        this.attributeName = StringUtils.trim(attributeKey.substring(idx + 1));

        AtlasTypeRegistry typeRegistry = context != null ? context.getTypeRegistry() : null;

        if (typeRegistry != null) {
            String typeName = StringUtils.trim(attributeKey.substring(0, idx));

            this.entityType = typeRegistry.getEntityTypeByName(typeName);
        } else {
            this.entityType = null;
        }
    } else {
        this.entityType    = null;
        this.attributeName = attributeKey;
    }
}
 
Example #2
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private static List<AtlasEntityDef> toAtlasEntityDefs(List<HierarchicalTypeDefinition<ClassType>> classTypeDefinitions,
                                                      AtlasTypeRegistry registry) throws AtlasBaseException {
    List<AtlasEntityDef> atlasEntityDefs = new ArrayList<AtlasEntityDef>();

    for (HierarchicalTypeDefinition<ClassType> classType : classTypeDefinitions) {
        List<AtlasAttributeDef> attrDefs         = new ArrayList<AtlasAttributeDef>();
        AtlasEntityDef          atlasEntityDef   = new AtlasEntityDef();
        String                  classTypeDefName = classType.typeName;

        atlasEntityDef.setName(classTypeDefName);
        atlasEntityDef.setDescription(classType.typeDescription);
        atlasEntityDef.setTypeVersion(classType.typeVersion);
        atlasEntityDef.setSuperTypes(classType.superTypes);

        AttributeDefinition[] attrDefinitions = classType.attributeDefinitions;
        for (AttributeDefinition oldAttr : attrDefinitions) {
            AtlasAttributeDef newAttr = toAtlasAttributeDef(oldAttr);
            attrDefs.add(newAttr);
        }

        atlasEntityDef.setAttributeDefs(attrDefs);
        atlasEntityDefs.add(atlasEntityDef);
    }

    return atlasEntityDefs;
}
 
Example #3
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry)
                                                                                         throws AtlasBaseException {
    String                typeName    = entityType.getEntityDef().getName();
    String                typeDesc    = entityType.getEntityDef().getDescription();
    String                typeVersion = entityType.getEntityDef().getTypeVersion();
    ImmutableSet          superTypes  = ImmutableSet.copyOf(entityType.getEntityDef().getSuperTypes());
    AttributeDefinition[] attributes  = getAttributes(entityType, registry);

    HierarchicalTypeDefinition<ClassType> classType = TypesUtil.createClassTypeDef(typeName, typeDesc, typeVersion,
                                                                                   superTypes, attributes);
    TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
                                         ImmutableList.<StructTypeDefinition>of(),
                                         ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
                                         ImmutableList.of(classType));

    return ret;
}
 
Example #4
Source File: SuggestionsRequestHandlerPatch.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void apply() throws AtlasBaseException {
    AtlasTypeRegistry          typeRegistry = context.getTypeRegistry();
    Collection<AtlasEntityDef> entityDefs   = typeRegistry.getAllEntityDefs();

    if (CollectionUtils.isNotEmpty(entityDefs)) {
        SolrIndexHelper indexHelper     = new SolrIndexHelper(typeRegistry);
        ChangedTypeDefs changedTypeDefs = new ChangedTypeDefs(null, new ArrayList<>(entityDefs), null);

        indexHelper.onChange(changedTypeDefs);
    }

    setStatus(APPLIED);

    LOG.info("SuggestionsRequestHandlerPatch.apply(): patchId={}, status={}", getPatchId(), getStatus());
}
 
Example #5
Source File: RestUtilsTest.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private List<AtlasEntityDef> convertV1toV2(List<HierarchicalTypeDefinition<ClassType>> types)
        throws AtlasBaseException {

    ImmutableList<HierarchicalTypeDefinition<ClassType>> classTypeList = ImmutableList
            .<HierarchicalTypeDefinition<ClassType>> builder().addAll(types).build();

    TypesDef toConvert = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition> of(),
            ImmutableList.<StructTypeDefinition> of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>> of(),
            classTypeList);

    String json = TypesSerialization.toJson(toConvert);
    AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry();
    AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry);
    List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs();
    return convertedEntityDefs;
}
 
Example #6
Source File: TypeConverterUtil.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static TypesDef toTypesDef(AtlasType type, AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    final TypesDef ret;

    if (type instanceof AtlasEnumType) {
        ret = TypeConverterUtil.enumToTypesDef((AtlasEnumType) type);
    } else if (type instanceof AtlasEntityType) {
        ret = TypeConverterUtil.entityToTypesDef((AtlasEntityType) type, typeRegistry);
    } else if (type instanceof AtlasClassificationType) {
        ret = TypeConverterUtil.classificationToTypesDef((AtlasClassificationType) type, typeRegistry);
    } else if (type instanceof AtlasStructType) {
        ret = TypeConverterUtil.structToTypesDef((AtlasStructType) type, typeRegistry);
    } else {
        ret = new TypesDef();
    }

    return ret;
}
 
Example #7
Source File: UniqueAttributePatch.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void submitVerticesToUpdate(WorkItemManager manager) {
    AtlasTypeRegistry typeRegistry = getTypeRegistry();
    AtlasGraph        graph        = getGraph();

    for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        LOG.info("finding entities of type {}", entityType.getTypeName());

        Iterable<Object> iterable = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, entityType.getTypeName()).vertexIds();
        int              count    = 0;

        for (Iterator<Object> iter = iterable.iterator(); iter.hasNext(); ) {
            Object vertexId = iter.next();

            manager.checkProduce((Long) vertexId);

            count++;
        }

        LOG.info("found {} entities of type {}", count, entityType.getTypeName());
    }
}
 
Example #8
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static TypesDef toTypesDef(AtlasType type, AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
    final TypesDef ret;

    if (type instanceof AtlasEnumType) {
        ret = TypeConverterUtil.enumToTypesDef((AtlasEnumType) type);
    } else if (type instanceof AtlasEntityType) {
        ret = TypeConverterUtil.entityToTypesDef((AtlasEntityType) type, typeRegistry);
    } else if (type instanceof AtlasClassificationType) {
        ret = TypeConverterUtil.classificationToTypesDef((AtlasClassificationType) type, typeRegistry);
    } else if (type instanceof AtlasStructType) {
        ret = TypeConverterUtil.structToTypesDef((AtlasStructType) type, typeRegistry);
    } else {
        ret = new TypesDef();
    }

    return ret;
}
 
Example #9
Source File: ClassificationAssociatorTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
private String[] setupUpdater(String entityHeaderFileName, String entityFileName, int expectedSummaryLength) throws IOException {
    AtlasEntityHeaders entityHeaderMap = getEntityHeaderMapFromFile(entityHeaderFileName);

    AtlasEntityType hiveTable = mock(AtlasEntityType.class);
    AtlasEntityStore entitiesStore = mock(AtlasEntityStore.class);
    AtlasTypeRegistry typeRegistry = mock(AtlasTypeRegistry.class);
    AtlasGraph atlasGraph = mock(AtlasGraph.class);

    when(typeRegistry.getEntityTypeByName(anyString())).thenReturn(hiveTable);
    when(hiveTable.getTypeName()).thenReturn("hive_column");

    ClassificationAssociatorUpdaterForSpy updater = new ClassificationAssociatorUpdaterForSpy(atlasGraph, typeRegistry, entitiesStore, entityFileName);
    String summary = updater.setClassifications(entityHeaderMap.getGuidHeaderMap());

    TypeReference<String[]> typeReference = new TypeReference<String[]>() {};
    String[] summaryArray = AtlasJson.fromJson(summary, typeReference);
    assertEquals(summaryArray.length, expectedSummaryLength);

    return summaryArray;
}
 
Example #10
Source File: AuditsWriter.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static String getParentEntityGuid(AtlasTypeRegistry typeRegistry, AtlasEntityStore entityStore, String defaultGuid) throws AtlasBaseException {
    AtlasEntity.AtlasEntityWithExtInfo extInfo = entityStore.getById(defaultGuid);
    if (extInfo == null || extInfo.getEntity() == null) {
        return null;
    }

    String typeName = extInfo.getEntity().getTypeName();
    if (!typeName.equals(ENTITY_TYPE_HIVE_TABLE) && !typeName.equals(ENTITY_TYPE_HIVE_COLUMN)) {
        return null;
    }

    String hiveDBQualifiedName = extractHiveDBQualifiedName((String) extInfo.getEntity().getAttribute(EntityGraphRetriever.QUALIFIED_NAME));
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(ENTITY_TYPE_HIVE_DB);
    return entityStore.getGuidByUniqueAttributes(entityType, Collections.singletonMap(EntityGraphRetriever.QUALIFIED_NAME, hiveDBQualifiedName));
}
 
Example #11
Source File: EntityConsumerBuilder.java    From atlas with Apache License 2.0 5 votes vote down vote up
public EntityConsumerBuilder(AtlasTypeRegistry typeRegistry, AtlasGraph atlasGraph, AtlasEntityStoreV2 entityStore, EntityGraphRetriever entityRetriever,
                             AtlasGraph atlasGraphBulk, AtlasEntityStoreV2 entityStoreBulk, EntityGraphRetriever entityRetrieverBulk,
                             int batchSize) {
    this.typeRegistry = typeRegistry;

    this.atlasGraph = atlasGraph;
    this.entityStore = entityStore;
    this.entityRetriever = entityRetriever;

    this.atlasGraphBulk = atlasGraphBulk;
    this.entityStoreBulk = entityStoreBulk;
    this.entityRetrieverBulk = entityRetrieverBulk;

    this.batchSize = batchSize;
}
 
Example #12
Source File: MigrationImport.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityStoreV2 createEntityStore(AtlasGraph graph, AtlasTypeRegistry typeRegistry) {
    FullTextMapperV2Nop fullTextMapperV2 = new FullTextMapperV2Nop();
    IAtlasEntityChangeNotifier entityChangeNotifier = new EntityChangeNotifierNop();
    DeleteHandlerDelegate deleteDelegate = new DeleteHandlerDelegate(graph, typeRegistry);
    AtlasFormatConverters formatConverters = new AtlasFormatConverters(typeRegistry);

    AtlasInstanceConverter instanceConverter = new AtlasInstanceConverter(graph, typeRegistry, formatConverters);
    AtlasRelationshipStore relationshipStore = new AtlasRelationshipStoreV2(graph, typeRegistry, deleteDelegate, entityChangeNotifier);
    EntityGraphMapper entityGraphMapper = new EntityGraphMapper(deleteDelegate, typeRegistry, graph, relationshipStore, entityChangeNotifier, instanceConverter, fullTextMapperV2);

    return new AtlasEntityStoreV2(graph, deleteDelegate, typeRegistry, entityChangeNotifier, entityGraphMapper);
}
 
Example #13
Source File: ClassificationAssociatorTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void updaterIncorrectType_ReturnsError() throws IOException {
    AtlasEntityHeaders entityHeaderMap = getEntityHeaderMapFromFile("header-PII");
    AtlasEntityStore entitiesStore = mock(AtlasEntityStore.class);

    AtlasTypeRegistry typeRegistry = mock(AtlasTypeRegistry.class);
    when(typeRegistry.getEntityTypeByName(anyString())).thenReturn(null);

    AtlasGraph atlasGraph = mock(AtlasGraph.class);
    ClassificationAssociator.Updater updater = new ClassificationAssociator.Updater(atlasGraph, typeRegistry, entitiesStore);
    String summary = updater.setClassifications(entityHeaderMap.getGuidHeaderMap());

    assertTrue(summary.contains("hive_"));
    assertTrue(summary.contains(STATUS_SKIPPED));
}
 
Example #14
Source File: TypeConverterUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static TypesDef classificationToTypesDef(AtlasClassificationType classificationType, AtlasTypeRegistry registry) {
    String                    typeName    = classificationType.getClassificationDef().getName();
    String                    typeDesc    = classificationType.getClassificationDef().getDescription();
    String                    typeVersion = classificationType.getClassificationDef().getTypeVersion();
    Set<String>               superTypes  = new HashSet<>(classificationType.getClassificationDef().getSuperTypes());
    List<AttributeDefinition> attributes  = getAttributes(classificationType, registry);

    TraitTypeDefinition traitTypeDef = new TraitTypeDefinition(typeName, typeDesc, typeVersion, attributes, superTypes);

    TypesDef ret = new TypesDef(null, null, Arrays.asList(traitTypeDef), null);

    return ret;
}
 
Example #15
Source File: DiscoveryREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Inject
public DiscoveryREST(AtlasTypeRegistry typeRegistry, AtlasDiscoveryService discoveryService, Configuration configuration) {
    this.typeRegistry           = typeRegistry;
    this.discoveryService       = discoveryService;
    this.maxFullTextQueryLength = configuration.getInt(Constants.MAX_FULLTEXT_QUERY_STR_LENGTH, 4096);
    this.maxDslQueryLength      = configuration.getInt(Constants.MAX_DSL_QUERY_STR_LENGTH, 4096);
}
 
Example #16
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Inject
public AtlasEntityStoreV2(AtlasGraph graph, DeleteHandlerDelegate deleteDelegate, AtlasTypeRegistry typeRegistry,
                          IAtlasEntityChangeNotifier entityChangeNotifier, EntityGraphMapper entityGraphMapper) {
    this.graph                = graph;
    this.deleteDelegate       = deleteDelegate;
    this.typeRegistry         = typeRegistry;
    this.entityChangeNotifier = entityChangeNotifier;
    this.entityGraphMapper    = entityGraphMapper;
    this.entityRetriever      = new EntityGraphRetriever(graph, typeRegistry);
}
 
Example #17
Source File: EntityNotificationTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAllTraitsSuperTraits() throws Exception {
    AtlasTypeRegistry       typeRegistry        = mock(AtlasTypeRegistry.class);
    String                  traitName           = "MyTrait";
    Struct                  myTrait             = new Struct(traitName);
    String                  superTraitName      = "MySuperTrait";
    AtlasClassificationType traitType           = mock(AtlasClassificationType.class);
    Set<String>             superTypeNames      = Collections.singleton(superTraitName);
    AtlasClassificationType superTraitType      = mock(AtlasClassificationType.class);
    Set<String>             superSuperTypeNames = Collections.emptySet();
    Referenceable           entity              = getEntity("id", myTrait);

    when(typeRegistry.getClassificationTypeByName(traitName)).thenReturn(traitType);
    when(typeRegistry.getClassificationTypeByName(superTraitName)).thenReturn(superTraitType);

    when(traitType.getAllSuperTypes()).thenReturn(superTypeNames);
    when(superTraitType.getAllSuperTypes()).thenReturn(superSuperTypeNames);

    EntityNotificationV1 entityNotification = new EntityNotificationV1(entity, OperationType.TRAIT_ADD, typeRegistry);

    List<Struct> allTraits = entityNotification.getAllTraits();

    assertEquals(2, allTraits.size());

    for (Struct trait : allTraits) {
        String typeName = trait.getTypeName();

        assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
    }
}
 
Example #18
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private static AttributeDefinition[] getAttributes(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException {
    List<AttributeDefinition> ret      = new ArrayList<>();
    List<AtlasAttributeDef>   attrDefs = structType.getStructDef().getAttributeDefs();

    if (CollectionUtils.isNotEmpty(attrDefs)) {
        for (AtlasAttributeDef attrDef : attrDefs) {
            AtlasAttribute attribute = structType.getAttribute(attrDef.getName());

            ret.add(AtlasStructDefStoreV1.toAttributeDefintion(attribute));
        }
    }

    return ret.toArray(new AttributeDefinition[ret.size()]);
}
 
Example #19
Source File: AtlasInstanceConverter.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Inject
public AtlasInstanceConverter(AtlasGraph graph, AtlasTypeRegistry typeRegistry, AtlasFormatConverters instanceFormatters) {
    this.typeRegistry                                = typeRegistry;
    this.instanceFormatters                          = instanceFormatters;
    this.entityGraphRetriever                        = new EntityGraphRetriever(graph, typeRegistry);
    this.entityGraphRetrieverIgnoreRelationshipAttrs = new EntityGraphRetriever(graph, typeRegistry, true);
}
 
Example #20
Source File: TypeConverterUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasTypesDef toAtlasTypesDef(String typeDefinition, AtlasTypeRegistry registry) throws AtlasBaseException {
    AtlasTypesDef ret = new AtlasTypesDef();

    try {
        if (StringUtils.isEmpty(typeDefinition)) {
            throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
        }

        TypesDef typesDef = AtlasType.fromV1Json(typeDefinition, TypesDef.class);
        if (CollectionUtils.isNotEmpty(typesDef.getEnumTypes())) {
            List<AtlasEnumDef> enumDefs = toAtlasEnumDefs(typesDef.getEnumTypes());
            ret.setEnumDefs(enumDefs);
        }

        if (CollectionUtils.isNotEmpty(typesDef.getStructTypes())) {
            List<AtlasStructDef> structDefs = toAtlasStructDefs(typesDef.getStructTypes());
            ret.setStructDefs(structDefs);
        }

        if (CollectionUtils.isNotEmpty(typesDef.getClassTypes())) {
            List<AtlasEntityDef> entityDefs = toAtlasEntityDefs(typesDef.getClassTypes(), registry);
            ret.setEntityDefs(entityDefs);
        }

        if (CollectionUtils.isNotEmpty(typesDef.getTraitTypes())) {
            List<AtlasClassificationDef> classificationDefs = toAtlasClassificationDefs(typesDef.getTraitTypes());
            ret.setClassificationDefs(classificationDefs);
        }

    } catch (Exception e) {
        LOG.error("Invalid type definition = {}", typeDefinition, e);
        throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
    }

    return ret;
}
 
Example #21
Source File: AtlasTypeDefGraphStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Inject
public AtlasTypeDefGraphStoreV2(AtlasTypeRegistry typeRegistry,
                                Set<TypeDefChangeListener> typeDefChangeListeners,
                                AtlasGraph atlasGraph) {
    super(typeRegistry, typeDefChangeListeners);
    this.atlasGraph = atlasGraph;

    LOG.debug("<== AtlasTypeDefGraphStoreV1()");
}
 
Example #22
Source File: ClassificationTextPatch.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void submitVerticesToUpdate(WorkItemManager manager) {
    AtlasTypeRegistry typeRegistry = getTypeRegistry();
    AtlasGraph        graph        = getGraph();
    Set<Long>         vertexIds    = new HashSet<>();

    for (AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        LOG.info("finding classification of type {}", classificationType.getTypeName());

        Iterable<AtlasVertex> iterable = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, classificationType.getTypeName()).vertices();
        int                   count    = 0;

        for (Iterator<AtlasVertex> iter = iterable.iterator(); iter.hasNext(); ) {
            AtlasVertex         classificationVertex = iter.next();
            Iterable<AtlasEdge> edges                = classificationVertex.getEdges(AtlasEdgeDirection.IN);

            for (AtlasEdge edge : edges) {
                AtlasVertex entityVertex = edge.getOutVertex();
                Long        vertexId     = (Long) entityVertex.getId();

                if (vertexIds.contains(vertexId)) {
                    continue;
                }

                vertexIds.add(vertexId);

                manager.checkProduce(vertexId);
            }

            count++;
        }

        LOG.info("found {} classification of type {}", count, classificationType.getTypeName());
    }

    LOG.info("found {} entities with classifications", vertexIds.size());
}
 
Example #23
Source File: ModelTestUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasClassificationDef newClassificationDef(AtlasTypeRegistry typesRegistry,
                                                          AtlasClassificationDef[] superTypes) {
    int classificationDefIdx = IDX_CLASSIFICATION_DEF.getAndIncrement();

    AtlasClassificationDef ret = new AtlasClassificationDef();

    ret.setName(PREFIX_CLASSIFICATION_DEF + classificationDefIdx);
    ret.setDescription(ret.getName());
    ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME));

    if (superTypes != null) {
        for (AtlasClassificationDef superType : superTypes) {
            ret.addSuperType(superType.getName());
        }
    }

    AtlasTransientTypeRegistry ttr    = null;
    boolean                    commit = false;

    try {
        ttr = typesRegistry.lockTypeRegistryForUpdate();

        ttr.addType(ret);

        commit = true;
    } catch (AtlasBaseException excp) {
        LOG.error("failed to create classification-def", excp);

        ret = null;
    } finally {
        typesRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }

    return ret;
}
 
Example #24
Source File: DataMigrationService.java    From atlas with Apache License 2.0 5 votes vote down vote up
public FileImporter(GraphDBMigrator migrator, AtlasTypeDefStore typeDefStore, AtlasTypeRegistry typeRegistry,
                    AtlasTypeDefStoreInitializer storeInitializer,
                    String directoryName, GraphBackedSearchIndexer indexer) {
    this.migrator         = migrator;
    this.typeDefStore     = typeDefStore;
    this.typeRegistry     = typeRegistry;
    this.storeInitializer = storeInitializer;
    this.importDirectory  = directoryName;
    this.indexer          = indexer;
}
 
Example #25
Source File: GremlinQueryComposerTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private String getGremlinQuery(String dsl, AtlasDSLParser.QueryContext queryContext, int expectedNumberOfErrors) {
    AtlasTypeRegistry             registry = mock(AtlasTypeRegistry.class);
    org.apache.atlas.query.Lookup lookup   = new TestLookup(registry);
    GremlinQueryComposer.Context  context  = new GremlinQueryComposer.Context(lookup);
    AtlasDSL.QueryMetadata queryMetadata   = new AtlasDSL.QueryMetadata(queryContext);

    GremlinQueryComposer gremlinQueryComposer = new GremlinQueryComposer(lookup, context, queryMetadata);
    DSLVisitor           qv                   = new DSLVisitor(gremlinQueryComposer);
    qv.visit(queryContext);

    String s = gremlinQueryComposer.get();
    int actualNumberOfErrors = gremlinQueryComposer.getErrorList().size();
    assertEquals(actualNumberOfErrors, expectedNumberOfErrors, dsl);
    return s;
}
 
Example #26
Source File: ModelTestUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasEntity newEntity(AtlasEntityDef entityDef, AtlasTypeRegistry typesRegistry) {
    AtlasEntity ret = null;

    AtlasEntityType entityType = typesRegistry.getEntityTypeByName(entityDef.getName());

    if (entityType != null) {
        ret = entityType.createDefaultValue();
    } else {
        LOG.error("failed to get entity-type {}", entityDef.getName());
    }

    return ret;
}
 
Example #27
Source File: AtlasFormatConverters.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Inject
public AtlasFormatConverters(AtlasTypeRegistry typeRegistry) {
    registerConverter(new AtlasPrimitiveFormatConverter(this, typeRegistry));
    registerConverter(new AtlasEnumFormatConverter(this, typeRegistry));
    registerConverter(new AtlasStructFormatConverter(this, typeRegistry));
    registerConverter(new AtlasClassificationFormatConverter(this, typeRegistry));
    registerConverter(new AtlasEntityFormatConverter(this, typeRegistry));
    registerConverter(new AtlasArrayFormatConverter(this, typeRegistry));
    registerConverter(new AtlasMapFormatConverter(this, typeRegistry));
    registerConverter(new AtlasObjectIdConverter(this, typeRegistry));
}
 
Example #28
Source File: ModelTestUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasStructDef newStructDef(AtlasTypeRegistry typesRegistry) {
    int structDefIdx = IDX_STRUCT_DEF.getAndIncrement();

    AtlasStructDef ret = new AtlasStructDef();

    ret.setName(PREFIX_STRUCT_DEF + structDefIdx);
    ret.setDescription(ret.getName());
    ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME));

    AtlasTransientTypeRegistry ttr    = null;
    boolean                    commit = false;

    try {
        ttr = typesRegistry.lockTypeRegistryForUpdate();

        ttr.addType(ret);

        commit = true;
    } catch (AtlasBaseException excp) {
        LOG.error("failed to create struct-def", excp);

        ret = null;
    } finally {
        typesRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }

    return ret;
}
 
Example #29
Source File: EntityResource.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Created by the Guice ServletModule and injected with the
 * configured MetadataService.
 *
 * @param metadataService metadata service handle
 */
@Inject
public EntityResource(MetadataService metadataService, AtlasInstanceConverter restAdapters,
                      AtlasEntityStore entitiesStore, AtlasTypeRegistry typeRegistry, EntityREST entityREST) {
    this.metadataService = metadataService;
    this.restAdapters    = restAdapters;
    this.entitiesStore   = entitiesStore;
    this.typeRegistry    = typeRegistry;
    this.entityREST    = entityREST;
}
 
Example #30
Source File: RestUtilsTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasTypeRegistry createRegistry(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
    AtlasTypeRegistry reg = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry tmp = reg.lockTypeRegistryForUpdate();
    tmp.addTypes(toConvert);
    reg.releaseTypeRegistryForUpdate(tmp, true);
    return reg;
}