use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class ImportTypeDefProcessor method processTypes.
public void processTypes(AtlasTypesDef typeDefinitionMap, AtlasImportResult result) throws AtlasBaseException {
setGuidToEmpty(typeDefinitionMap);
typeAttributeDifference.updateTypes(typeDefinitionMap, result);
AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typeDefinitionMap, this.typeRegistry);
if (!typesToCreate.isEmpty()) {
typeDefStore.createTypesDef(typesToCreate);
updateMetricsForTypesDef(typesToCreate, result);
}
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class TypeConverterUtil method toAtlasTypesDef.
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;
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class TypesREST method getTypeDefHeaders.
/**
* Bulk retrieval API for all type definitions returned as a list of minimal information header
* @return List of AtlasTypeDefHeader {@link AtlasTypeDefHeader}
* @throws AtlasBaseException
* @HTTP 200 Returns a list of {@link AtlasTypeDefHeader} matching the search criteria
* or an empty list if no match.
*/
@GET
@Path("/typedefs/headers")
@Produces(Servlets.JSON_MEDIA_TYPE)
public List<AtlasTypeDefHeader> getTypeDefHeaders(@Context HttpServletRequest httpServletRequest) throws AtlasBaseException {
SearchFilter searchFilter = getSearchFilter(httpServletRequest);
AtlasTypesDef searchTypesDef = typeDefStore.searchTypesDef(searchFilter);
return AtlasTypeUtil.toTypeDefHeader(searchTypesDef);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class QuickStartV2 method verifyTypesCreated.
private void verifyTypesCreated() throws Exception {
MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
for (String typeName : TYPES) {
searchParams.clear();
searchParams.add(SearchFilter.PARAM_NAME, typeName);
SearchFilter searchFilter = new SearchFilter(searchParams);
AtlasTypesDef searchDefs = atlasClientV2.getAllTypeDefs(searchFilter);
assert (!searchDefs.isEmpty());
System.out.println("Created type [" + typeName + "]");
}
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class TypesResource method update.
/**
* Update of existing types - if the given type doesn't exist, creates new type
* Allowed updates are:
* 1. Add optional attribute
* 2. Change required to optional attribute
* 3. Add super types - super types shouldn't contain any required attributes
* @param request
* @return
*/
@PUT
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response update(@Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TypesResource.update()");
}
AtlasPerfTracer perf = null;
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
}
try {
final String typeDefinition = Servlets.getRequestPayload(request);
if (LOG.isDebugEnabled()) {
LOG.debug("Updating type with definition {} ", typeDefinition);
}
AtlasTypesDef updateTypesDef = TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry);
AtlasTypesDef updatedTypesDef = typeDefStore.createUpdateTypesDef(updateTypesDef);
List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef);
List<Map<String, Object>> typesResponse = new ArrayList<>(typeNames.size());
for (String typeName : typeNames) {
typesResponse.add(Collections.singletonMap(AtlasClient.NAME, typeName));
}
Map<String, Object> response = new HashMap<>();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPES, typesResponse);
return Response.ok().entity(AtlasJson.toV1Json(response)).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to persist types", e);
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (IllegalArgumentException e) {
LOG.error("Unable to persist types", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to persist types", e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to persist types", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== TypesResource.update()");
}
}
}
Aggregations