Search in sources :

Example 61 with AtlasTypesDef

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

the class AtlasTypeDefGraphStore method createUpdateTypesDef.

@Override
@GraphTransaction
public AtlasTypesDef createUpdateTypesDef(AtlasTypesDef typesToCreate, AtlasTypesDef typesToUpdate) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.createUpdateTypesDef({}, {})", typesToCreate, typesToUpdate);
    }
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    if (!typesToUpdate.isEmpty()) {
        ttr.updateTypesWithNoRefResolve(typesToUpdate);
    }
    // Translate any NOT FOUND errors to BAD REQUEST
    tryTypeCreation(typesToCreate, ttr);
    AtlasTypesDef ret = addToGraphStore(typesToCreate, ttr);
    if (!typesToUpdate.isEmpty()) {
        AtlasTypesDef updatedTypes = updateGraphStore(typesToUpdate, ttr);
        if (CollectionUtils.isNotEmpty(updatedTypes.getEnumDefs())) {
            for (AtlasEnumDef enumDef : updatedTypes.getEnumDefs()) {
                ret.getEnumDefs().add(enumDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getStructDefs())) {
            for (AtlasStructDef structDef : updatedTypes.getStructDefs()) {
                ret.getStructDefs().add(structDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getClassificationDefs())) {
            for (AtlasClassificationDef classificationDef : updatedTypes.getClassificationDefs()) {
                ret.getClassificationDefs().add(classificationDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getEntityDefs())) {
            for (AtlasEntityDef entityDef : updatedTypes.getEntityDefs()) {
                ret.getEntityDefs().add(entityDef);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.createUpdateTypesDef({}, {}): {}", typesToCreate, typesToUpdate, ret);
    }
    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) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 62 with AtlasTypesDef

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

the class AtlasTypeDefGraphStore method searchTypesDef.

@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
    final AtlasTypesDef typesDef = new AtlasTypesDef();
    Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);
    for (AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
        if (searchPredicates.evaluate(enumType)) {
            typesDef.getEnumDefs().add(enumType.getEnumDef());
        }
    }
    for (AtlasStructType structType : typeRegistry.getAllStructTypes()) {
        if (searchPredicates.evaluate(structType)) {
            typesDef.getStructDefs().add(structType.getStructDef());
        }
    }
    for (AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        if (searchPredicates.evaluate(classificationType)) {
            typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
        }
    }
    for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        if (searchPredicates.evaluate(entityType)) {
            typesDef.getEntityDefs().add(entityType.getEntityDef());
        }
    }
    return typesDef;
}
Also used : AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Predicate(org.apache.commons.collections.Predicate)

Example 63 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-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) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 64 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-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()");
    }
    JSONArray typesResponse = new JSONArray();
    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 = typesREST.updateAtlasTypeDefs(updateTypesDef);
        List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef);
        for (int i = 0; i < typeNames.size(); i++) {
            final String name = typeNames.get(i);
            typesResponse.put(new JSONObject() {

                {
                    put(AtlasClient.NAME, name);
                }
            });
        }
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.TYPES, typesResponse);
        return Response.ok().entity(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 : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONArray(org.codehaus.jettison.json.JSONArray) 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)64 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)30 Test (org.testng.annotations.Test)25 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)22 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)13 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)9 SearchFilter (org.apache.atlas.model.SearchFilter)8 ArrayList (java.util.ArrayList)7 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)7 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 HashMap (java.util.HashMap)6 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)6 BeforeClass (org.testng.annotations.BeforeClass)6 BeforeTest (org.testng.annotations.BeforeTest)5 Produces (javax.ws.rs.Produces)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)4