Search in sources :

Example 11 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class EntityJerseyResourceIT method testGetTraitDefinitionForEntity.

@Test
public void testGetTraitDefinitionForEntity() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    String traitDefinitionAsJSON = AtlasType.toV1Json(typesDef);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    createType(AtlasType.toV1Json(typesDef));
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    Struct traitDef = atlasClientV1.getTraitDefinition(guid, traitName);
    Assert.assertEquals(traitDef.getTypeName(), traitName);
    List<Struct> allTraitDefs = atlasClientV1.listTraitDefinitions(guid);
    System.out.println(allTraitDefs.toString());
    Assert.assertEquals(allTraitDefs.size(), 8);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 12 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class TypesResource method getDefinition.

/**
 * Fetch the complete definition of a given type name which is unique.
 *
 * @param typeName name of a type which is unique.
 */
@GET
@Path("{typeName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getDefinition(@Context HttpServletRequest request, @PathParam("typeName") String typeName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TypesResource.getDefinition({})", typeName);
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")");
    }
    Map<String, Object> response = new HashMap<>();
    try {
        TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);
        ;
        response.put(AtlasClient.TYPENAME, typeName);
        response.put(AtlasClient.DEFINITION, typesDef);
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        return Response.ok(AtlasJson.toV1Json(response)).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== TypesResource.getDefinition({})", typeName);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class TypeConverterUtil method structToTypesDef.

private static TypesDef structToTypesDef(AtlasStructType structType, AtlasTypeRegistry registry) {
    String typeName = structType.getStructDef().getName();
    String typeDesc = structType.getStructDef().getDescription();
    String typeVersion = structType.getStructDef().getTypeVersion();
    List<AttributeDefinition> attributes = getAttributes(structType, registry);
    StructTypeDefinition structTypeDef = new StructTypeDefinition(typeName, typeDesc, typeVersion, attributes);
    TypesDef ret = new TypesDef(null, Arrays.asList(structTypeDef), null, null);
    return ret;
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition) StructTypeDefinition(org.apache.atlas.v1.model.typedef.StructTypeDefinition)

Example 14 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class TypeConverterUtil method enumToTypesDef.

private static TypesDef enumToTypesDef(AtlasEnumType enumType) {
    AtlasEnumDef enumDef = enumType.getEnumDef();
    String enumName = enumDef.getName();
    String enumDesc = enumDef.getDescription();
    String enumVersion = enumDef.getTypeVersion();
    List<EnumValue> enumValues = getEnumValues(enumDef.getElementDefs());
    EnumTypeDefinition enumTypeDef = new EnumTypeDefinition(enumName, enumDesc, enumVersion, enumValues);
    TypesDef ret = new TypesDef(Arrays.asList(enumTypeDef), null, null, null);
    return ret;
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) EnumValue(org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue) EnumTypeDefinition(org.apache.atlas.v1.model.typedef.EnumTypeDefinition) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 15 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class TypeConverterUtil method entityToTypesDef.

private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) {
    String typeName = entityType.getEntityDef().getName();
    String typeDesc = entityType.getEntityDef().getDescription();
    String typeVersion = entityType.getEntityDef().getTypeVersion();
    Set<String> superTypes = entityType.getEntityDef().getSuperTypes();
    List<AttributeDefinition> attributes = getAttributes(entityType, registry);
    ClassTypeDefinition classTypeDef = new ClassTypeDefinition(typeName, typeDesc, typeVersion, attributes, superTypes);
    TypesDef ret = new TypesDef(null, null, null, Arrays.asList(classTypeDef));
    return ret;
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition) ClassTypeDefinition(org.apache.atlas.v1.model.typedef.ClassTypeDefinition)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)8 Test (org.testng.annotations.Test)8 Id (org.apache.atlas.v1.model.instance.Id)7 TypesDef (org.apache.atlas.v1.model.typedef.TypesDef)7 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)6 Struct (org.apache.atlas.v1.model.instance.Struct)5 AtlasServiceException (org.apache.atlas.AtlasServiceException)3 AttributeDefinition (org.apache.atlas.v1.model.typedef.AttributeDefinition)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 TraitTypeDefinition (org.apache.atlas.v1.model.typedef.TraitTypeDefinition)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)1 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)1 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)1