Search in sources :

Example 66 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method updateGraphStore.

private AtlasTypesDef updateGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    AtlasTypesDef ret = new AtlasTypesDef();
    AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
    AtlasStructDefStore structDefStore = getStructDefStore(ttr);
    AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
    AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
    if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
        for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
            ret.getEnumDefs().add(enumDefStore.update(enumDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            ret.getStructDefs().add(structDefStore.update(structDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            ret.getClassificationDefs().add(classifiDefStore.update(classifiDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            ret.getEntityDefs().add(entityDefStore.update(entityDef));
        }
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 67 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project nifi by apache.

the class NiFiAtlasClient method registerNiFiTypeDefs.

/**
 * Create or update NiFi types in Atlas type system.
 * @param update If false, doesn't perform anything if there is existing type def for the name.
 */
public void registerNiFiTypeDefs(boolean update) throws AtlasServiceException {
    final Set<String> typeNames = ENTITIES.keySet();
    final Map<String, AtlasEntityDef> existingDefs = getTypeDefs(typeNames.toArray(new String[typeNames.size()])).getEntityDefs().stream().collect(Collectors.toMap(AtlasEntityDef::getName, Function.identity()));
    final AtomicBoolean shouldUpdate = new AtomicBoolean(false);
    final AtlasTypesDef type = new AtlasTypesDef();
    typeNames.stream().filter(typeName -> {
        final AtlasEntityDef existingDef = existingDefs.get(typeName);
        if (existingDef != null) {
            // type is already defined.
            if (!update) {
                return false;
            }
            shouldUpdate.set(true);
        }
        return true;
    }).forEach(typeName -> {
        final NiFiTypes.EntityDefinition def = ENTITIES.get(typeName);
        final AtlasEntityDef entity = new AtlasEntityDef();
        type.getEntityDefs().add(entity);
        entity.setName(typeName);
        Set<String> superTypes = new HashSet<>();
        List<AtlasAttributeDef> attributes = new ArrayList<>();
        def.define(entity, superTypes, attributes);
        entity.setSuperTypes(superTypes);
        entity.setAttributeDefs(attributes);
    });
    // Create or Update.
    final AtlasTypesDef atlasTypeDefsResult = shouldUpdate.get() ? atlasClient.updateAtlasTypeDefs(type) : atlasClient.createAtlasTypeDefs(type);
    logger.debug("Result={}", atlasTypeDefsResult);
}
Also used : AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) ATTR_INPUT_PORTS(org.apache.nifi.atlas.NiFiTypes.ATTR_INPUT_PORTS) TYPE_NIFI_FLOW(org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_FLOW) LoggerFactory(org.slf4j.LoggerFactory) ATTR_OUTPUT_PORTS(org.apache.nifi.atlas.NiFiTypes.ATTR_OUTPUT_PORTS) ATTR_QUEUES(org.apache.nifi.atlas.NiFiTypes.ATTR_QUEUES) DELETED(org.apache.nifi.atlas.NiFiFlow.EntityChangeType.DELETED) ATTR_QUALIFIED_NAME(org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME) UPDATED(org.apache.nifi.atlas.NiFiFlow.EntityChangeType.UPDATED) Matcher(java.util.regex.Matcher) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Map(java.util.Map) TYPE_NIFI_OUTPUT_PORT(org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT) CREATED(org.apache.nifi.atlas.NiFiFlow.EntityChangeType.CREATED) AtlasUtils.getComponentIdFromQualifiedName(org.apache.nifi.atlas.AtlasUtils.getComponentIdFromQualifiedName) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) AtlasServiceException(org.apache.atlas.AtlasServiceException) Set(java.util.Set) StringUtils(org.apache.nifi.util.StringUtils) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ATTR_URL(org.apache.nifi.atlas.NiFiTypes.ATTR_URL) Pattern(java.util.regex.Pattern) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) AtlasClientV2(org.apache.atlas.AtlasClientV2) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ATTR_OUTPUTS(org.apache.nifi.atlas.NiFiTypes.ATTR_OUTPUTS) TYPE_NIFI_FLOW_PATH(org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_FLOW_PATH) AtlasUtils.findIdByQualifiedName(org.apache.nifi.atlas.AtlasUtils.findIdByQualifiedName) AS_IS(org.apache.nifi.atlas.NiFiFlow.EntityChangeType.AS_IS) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) ATTR_INPUTS(org.apache.nifi.atlas.NiFiTypes.ATTR_INPUTS) ATTR_NAME(org.apache.nifi.atlas.NiFiTypes.ATTR_NAME) Logger(org.slf4j.Logger) AtlasUtils.toStr(org.apache.nifi.atlas.AtlasUtils.toStr) ATTR_FLOW_PATHS(org.apache.nifi.atlas.NiFiTypes.ATTR_FLOW_PATHS) TYPE_NIFI_INPUT_PORT(org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_INPUT_PORT) ATTR_DESCRIPTION(org.apache.nifi.atlas.NiFiTypes.ATTR_DESCRIPTION) ENTITIES(org.apache.nifi.atlas.NiFiTypes.ENTITIES) ATTR_GUID(org.apache.nifi.atlas.NiFiTypes.ATTR_GUID) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Tuple(org.apache.nifi.util.Tuple) TYPE_NIFI_QUEUE(org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_QUEUE) SearchFilter(org.apache.atlas.model.SearchFilter) ATTR_TYPENAME(org.apache.nifi.atlas.NiFiTypes.ATTR_TYPENAME) Collections(java.util.Collections) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) HashSet(java.util.HashSet)

Example 68 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.

the class TypesREST method getAllTypeDefs.

/**
 * Bulk retrieval API for retrieving all type definitions in Atlas
 * @return A composite wrapper object with lists of all type definitions
 * @throws Exception
 * @HTTP 200 {@link AtlasTypesDef} with type definitions matching the search criteria or else returns empty list of type definitions
 */
@GET
@Path("/typedefs")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasTypesDef getAllTypeDefs(@Context HttpServletRequest httpServletRequest) throws AtlasBaseException {
    SearchFilter searchFilter = getSearchFilter(httpServletRequest);
    AtlasTypesDef typesDef = typeDefStore.searchTypesDef(searchFilter);
    return typesDef;
}
Also used : SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 69 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.

the class EntityV2JerseyResourceIT method testGetTraitDefinitionForEntity.

@Test(dependsOnMethods = "testSubmitEntity")
public void testGetTraitDefinitionForEntity() throws Exception {
    traitName = "PII_Trait" + randomString();
    AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet());
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getClassificationDefs().add(piiTrait);
    createType(typesDef);
    AtlasClassificationDef classificationByName = atlasClientV2.getClassificationDefByName(traitName);
    assertNotNull(classificationByName);
    AtlasEntity hiveTable = createHiveTable();
    assertEquals(hiveTable.getClassifications().size(), 7);
    AtlasClassification piiClassification = new AtlasClassification(piiTrait.getName());
    atlasClientV2.addClassifications(hiveTable.getGuid(), Lists.newArrayList(piiClassification));
    AtlasClassifications classifications = atlasClientV2.getClassifications(hiveTable.getGuid());
    assertNotNull(classifications);
    assertTrue(classifications.getList().size() > 0);
    assertEquals(classifications.getList().size(), 8);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasClassifications(org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 70 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.

the class EntityV2JerseyResourceIT method testDeleteExistentTraitNonExistentForEntity.

@Test(dependsOnMethods = "testSubmitEntity")
public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
    final String guid = createHiveTable().getGuid();
    final String traitName = "PII_Trait" + randomString();
    AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet(), AtlasTypeUtil.createRequiredAttrDef("type", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getClassificationDefs().add(piiTrait);
    createType(typesDef);
    try {
        atlasClientV2.deleteClassification(guid, traitName);
        fail("Deletion should've failed for non-existent trait association");
    } catch (AtlasServiceException ex) {
        Assert.assertNotNull(ex.getStatus());
        assertEquals(ex.getStatus(), ClientResponse.Status.BAD_REQUEST);
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)119 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)54 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)39 Test (org.testng.annotations.Test)39 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)30 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)22 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)22 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)20 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)19 ArrayList (java.util.ArrayList)17 SearchFilter (org.apache.atlas.model.SearchFilter)15 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)15 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)14 BeforeClass (org.testng.annotations.BeforeClass)14 HashMap (java.util.HashMap)13 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)13 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)12 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)9 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7