Search in sources :

Example 11 with AtlasTypesDef

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);
    }
}
Also used : AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 12 with AtlasTypesDef

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;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 13 with AtlasTypesDef

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);
}
Also used : SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 14 with AtlasTypesDef

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 + "]");
    }
}
Also used : MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 15 with AtlasTypesDef

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()");
        }
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) HashMap(java.util.HashMap) Map(java.util.Map) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)118 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)18 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