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