org.apache.atlas.AtlasErrorCode Java Examples

The following examples show how to use org.apache.atlas.AtlasErrorCode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Updates classifications to an existing entity represented by a guid.
 * @param  guid globally unique identifier for the entity
 * @return classification for the given entity guid
 */
@PUT
@Path("/guid/{guid}/classifications")
public void updateClassifications(@PathParam("guid") final String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);

    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.updateClassifications(" + guid + ")");
        }

        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        entitiesStore.updateClassifications(guid, classifications);

    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #2
Source File: EntityGraphRetriever.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private AtlasVertex getEntityVertex(AtlasObjectId objId) throws AtlasBaseException {
    AtlasVertex ret = null;

    if (! AtlasTypeUtil.isValid(objId)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, objId.toString());
    }

    if (AtlasTypeUtil.isAssignedGuid(objId)) {
        ret = AtlasGraphUtilsV1.findByGuid(objId.getGuid());
    } else {
        AtlasEntityType     entityType     = typeRegistry.getEntityTypeByName(objId.getTypeName());
        Map<String, Object> uniqAttributes = objId.getUniqueAttributes();

        ret = AtlasGraphUtilsV1.getVertexByUniqueAttributes(entityType, uniqAttributes);
    }

    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, objId.toString());
    }

    return ret;
}
 
Example #3
Source File: AtlasStructDefStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef,
                                              AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException {
    Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName());

    String typeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);

    for (String referencedTypeName : referencedTypeNames) {
        if (!AtlasTypeUtil.isBuiltInType(referencedTypeName)) {
            AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName);

            if (referencedTypeVertex == null) {
                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, referencedTypeName, typeName, attributeDef.getName());
            }

            String label = AtlasGraphUtilsV2.getEdgeLabel(typeName, attributeDef.getName());

            typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label);
        }
    }
}
 
Example #4
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Bulk API to retrieve list of entities identified by its GUIDs.
 */
@GET
@Path("/bulk")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntitiesWithExtInfo getByGuids(@QueryParam("guid") List<String> guids) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getByGuids(" + guids + ")");
        }

        if (CollectionUtils.isEmpty(guids)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
        }

        return entitiesStore.getByIds(guids);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #5
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private AtlasEdge updateEdge(AtlasAttributeDef attributeDef, Object value, AtlasEdge currentEdge, final AtlasVertex entityVertex) throws AtlasBaseException {

        LOG.debug("Updating entity reference {} for reference attribute {}",  attributeDef.getName());
        // Update edge if it exists

        AtlasVertex currentVertex = currentEdge.getInVertex();
        String currentEntityId = getIdFromVertex(currentVertex);
        String newEntityId = getIdFromVertex(entityVertex);

        AtlasEdge newEdge = currentEdge;
        if (!currentEntityId.equals(newEntityId)) {
            // add an edge to the class vertex from the instance
            if (entityVertex != null) {
                try {
                    newEdge = graphHelper.getOrCreateEdge(currentEdge.getOutVertex(), entityVertex, currentEdge.getLabel());
                } catch (RepositoryException e) {
                    throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
                }

            }
        }
        return newEdge;
    }
 
Example #6
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the list of classifications for a given entity represented by a guid.
 * @param guid globally unique identifier for the entity
 * @return a list of classifications for the given entity guid
 */
@GET
@Path("/guid/{guid}/classifications")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassification.AtlasClassifications getClassifications(@PathParam("guid") String guid) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getClassifications(" + guid + ")");
        }

        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        return new AtlasClassification.AtlasClassifications(entitiesStore.getClassifications(guid));
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #7
Source File: AtlasInstanceConverter.java    From atlas with Apache License 2.0 6 votes vote down vote up
public AtlasEntitiesWithExtInfo toAtlasEntities(String[] jsonEntities) throws AtlasBaseException, AtlasException {
    Referenceable[] referenceables = new Referenceable[jsonEntities.length];

    for (int i = 0; i < jsonEntities.length; i++) {
        referenceables[i] = AtlasType.fromV1Json(jsonEntities[i], Referenceable.class);
    }

    AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
    ConverterContext           context   = new ConverterContext();

    for (Referenceable referenceable : referenceables) {
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());

        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), referenceable.getTypeName());
        }

        AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, context);

        context.addEntity(entity);
    }

    AtlasEntitiesWithExtInfo ret = context.getEntities();

    return ret;
}
 
Example #8
Source File: UserProfileServiceTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test(dependsOnMethods = { "updateSearch" })
public void deleteUsingGuid() throws AtlasBaseException {
    String               userName  = getIndexBasedUserName(0);
    String               queryName = getIndexBasedQueryName(1);
    AtlasUserSavedSearch expected  = userProfileService.getSavedSearch(userName, queryName);

    assertNotNull(expected);

    userProfileService.deleteSavedSearch(expected.getGuid());

    try {
        userProfileService.getSavedSearch(userName, queryName);
    } catch (AtlasBaseException ex) {
        assertEquals(ex.getAtlasErrorCode().name(), AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND.name());
    }
}
 
Example #9
Source File: GlossaryService.java    From atlas with Apache License 2.0 6 votes vote down vote up
@GraphTransaction
public AtlasGlossaryTerm getTerm(String termGuid) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.getTerm({})", termGuid);
    }
    if (Objects.isNull(termGuid)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "termGuid is null/empty");
    }


    AtlasGlossaryTerm atlasGlossary = getAtlasGlossaryTermSkeleton(termGuid);
    AtlasGlossaryTerm ret           = dataAccess.load(atlasGlossary);

    setInfoForRelations(ret);

    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.getTerm() : {}", ret);
    }
    return ret;
}
 
Example #10
Source File: TypeAttributeDifference.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void updateCollectionWithDifferingAttributes(List<AtlasStructDef.AtlasAttributeDef> difference,
                                                     AtlasStructDef existing,
                                                     AtlasStructDef.AtlasAttributeDef incoming) throws AtlasBaseException {
    AtlasStructDef.AtlasAttributeDef existingAttribute = existing.getAttribute(incoming.getName());
    if (existingAttribute == null) {
        AtlasRelationshipType relationshipType = AtlasTypeUtil.findRelationshipWithLegacyRelationshipEnd(existing.getName(), incoming.getName(), typeRegistry);

        if (relationshipType == null) {
            difference.add(incoming);
        }
    } else {
        if (!existingAttribute.getTypeName().equals(incoming.getTypeName())) {
            LOG.error("Attribute definition difference found: {}, {}", existingAttribute, incoming);
            throw new AtlasBaseException(AtlasErrorCode.INVALID_IMPORT_ATTRIBUTE_TYPE_CHANGED, existing.getName(), existingAttribute.getName(), existingAttribute.getTypeName(), incoming.getTypeName());
        }
    }
}
 
Example #11
Source File: UserProfileServiceTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test(dependsOnMethods = { "deleteSavedQuery" })
void deleteUser() throws AtlasBaseException {
    String           userName    = getIndexBasedUserName(0);
    AtlasUserProfile userProfile = userProfileService.getUserProfile(userName);

    if (userProfile.getSavedSearches() != null)  {
        for (AtlasUserSavedSearch savedSearch : userProfile.getSavedSearches()) {
            userProfileService.deleteSavedSearch(savedSearch.getGuid());
        }
    }

    userProfileService.deleteUserProfile(userName);

    try {
        userProfileService.getUserProfile(userName);
    } catch (AtlasBaseException ex) {
        assertEquals(ex.getAtlasErrorCode().name(), AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND.name());
    }
}
 
Example #12
Source File: AtlasInstanceConverter.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static AtlasBaseException toAtlasBaseException(AtlasException e) {
    if (e instanceof EntityExistsException) {
        return new AtlasBaseException(AtlasErrorCode.INSTANCE_ALREADY_EXISTS, e.getMessage());
    }

    if ( e instanceof EntityNotFoundException || e instanceof TraitNotFoundException) {
        return new AtlasBaseException(AtlasErrorCode.INSTANCE_NOT_FOUND, e.getMessage());
    }

    if ( e instanceof TypeNotFoundException) {
        return new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e.getMessage());
    }

    if (e instanceof ValueConversionException) {
        return new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, e, e.getMessage());
    }

    return new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
}
 
Example #13
Source File: ActiveInstanceState.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Update state of the active server instance.
 *
 * This method writes this instance's Server Address to a shared node in Zookeeper.
 * This information is used by other passive instances to locate the current active server.
 * @throws Exception
 * @param serverId ID of this server instance
 */
public void update(String serverId) throws AtlasBaseException {
    try {
        CuratorFramework client = curatorFactory.clientInstance();
        HAConfiguration.ZookeeperProperties zookeeperProperties =
                HAConfiguration.getZookeeperProperties(configuration);
        String atlasServerAddress = HAConfiguration.getBoundAddressForId(configuration, serverId);
        List<ACL> acls = Arrays.asList(
                new ACL[]{AtlasZookeeperSecurityProperties.parseAcl(zookeeperProperties.getAcl(),
                        ZooDefs.Ids.OPEN_ACL_UNSAFE.get(0))});
        Stat serverInfo = client.checkExists().forPath(getZnodePath(zookeeperProperties));
        if (serverInfo == null) {
            client.create().
                    withMode(CreateMode.EPHEMERAL).
                    withACL(acls).
                    forPath(getZnodePath(zookeeperProperties));
        }
        client.setData().forPath(getZnodePath(zookeeperProperties),
                atlasServerAddress.getBytes(Charset.forName("UTF-8")));
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.CURATOR_FRAMEWORK_UPDATE, e, "forPath: getZnodePath");
    }
}
 
Example #14
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public void deleteClassifications(final String guid, final List<String> classificationNames) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    if (CollectionUtils.isEmpty(classificationNames)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting classifications={} from entity={}", classificationNames, guid);
    }

    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);

    entityGraphMapper.deleteClassifications(guid, classificationNames);

    // notify listeners on classification deletion
    entityChangeNotifier.onClassificationDeletedFromEntity(guid, classificationNames);
}
 
Example #15
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Updates classifications to an existing entity represented by a guid.
 * @param  guid globally unique identifier for the entity
 * @return classification for the given entity guid
 */
@PUT
@Path("/guid/{guid}/classifications")
@Produces(Servlets.JSON_MEDIA_TYPE)
public void updateClassification(@PathParam("guid") final String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.updateClassification(" + guid + ")");
        }

        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }

        entitiesStore.updateClassifications(guid, classifications);

    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #16
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private Object mapCollectionElementsToVertex(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    switch(ctx.getAttrType().getTypeCategory()) {
    case PRIMITIVE:
    case ENUM:
        return ctx.getValue();

    case STRUCT:
        return mapStructValue(ctx, context);

    case OBJECT_ID_TYPE:
        AtlasEntityType instanceType = getInstanceType(ctx.getValue());
        ctx.setElementType(instanceType);
        return mapObjectIdValueUsingRelationship(ctx, context);

    case MAP:
    case ARRAY:
    default:
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, ctx.getAttrType().getTypeCategory().name());
    }
}
 
Example #17
Source File: EntityLineageService.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public SchemaDetails getSchemaForHiveTableByName(final String datasetName) throws AtlasBaseException {
    if (StringUtils.isEmpty(datasetName)) {
        // TODO: Complete error handling here
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST);
    }

    AtlasEntityType hive_table = atlasTypeRegistry.getEntityTypeByName("hive_table");

    Map<String, Object> lookupAttributes = new HashMap<>();
    lookupAttributes.put("qualifiedName", datasetName);
    String guid = AtlasGraphUtilsV2.getGuidByUniqueAttributes(hive_table, lookupAttributes);

    return getSchemaForHiveTableByGuid(guid);
}
 
Example #18
Source File: AtlasEntityGraphDiscoveryV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void validateAndNormalizeForUpdate(AtlasEntity entity) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();

    if (!AtlasTypeUtil.isValidGuid(entity.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
    }

    AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
    }

    validateCustomAttributes(entity);

    validateLabels(entity.getLabels());

    type.validateValueForUpdate(entity, entity.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
    }

    type.getNormalizedValueForUpdate(entity);
}
 
Example #19
Source File: QuickStart.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
Id table(String name, String description, Id dbId, Referenceable sd, String owner, String tableType,
        List<Referenceable> columns, String... traitNames) throws AtlasBaseException {
    try {
    Referenceable referenceable = new Referenceable(TABLE_TYPE, traitNames);
    referenceable.set("name", name);
    referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
    referenceable.set("description", description);
    referenceable.set("owner", owner);
    referenceable.set("tableType", tableType);
    referenceable.set("createTime", System.currentTimeMillis());
    referenceable.set("lastAccessTime", System.currentTimeMillis());
    referenceable.set("retention", System.currentTimeMillis());
    referenceable.set("db", dbId);
    referenceable.set("sd", sd);
    referenceable.set("columns", columns);

    return createInstance(referenceable);
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.QUICK_START, e, String.format("%s table entity creation failed", name));
    }
}
 
Example #20
Source File: AtlasAbstractDefStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void validateType(AtlasBaseTypeDef typeDef) throws AtlasBaseException {
    if (!isValidName(typeDef.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID_FORMAT, typeDef.getName(), typeDef.getCategory().name());
    }

    try {
        final boolean allowReservedKeywords = ApplicationProperties.get().getBoolean(ALLOW_RESERVED_KEYWORDS, true);

        if (!allowReservedKeywords && typeDef instanceof AtlasStructDef) {
            final List<AtlasStructDef.AtlasAttributeDef> attributeDefs = ((AtlasStructDef) typeDef).getAttributeDefs();
            for (AtlasStructDef.AtlasAttributeDef attrDef : attributeDefs) {
                if (AtlasDSL.Parser.isKeyword(attrDef.getName())) {
                    throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_NAME_INVALID, attrDef.getName(), typeDef.getCategory().name());
                }
            }
        }
    } catch (AtlasException e) {
        LOG.error("Exception while loading configuration ", e);
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "Could not load configuration");
    }
}
 
Example #21
Source File: GlossaryService.java    From atlas with Apache License 2.0 6 votes vote down vote up
@GraphTransaction
public List<AtlasGlossaryCategory> createCategories(List<AtlasGlossaryCategory> glossaryCategory) throws AtlasBaseException {
    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.createCategories({})", glossaryCategory);
    }
    if (Objects.isNull(glossaryCategory)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryCategory is null/empty");
    }

    List<AtlasGlossaryCategory> ret = new ArrayList<>();
    for (AtlasGlossaryCategory category : glossaryCategory) {
        ret.add(createCategory(category));
    }
    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.createCategories() : {}", ret);
    }
    return ret;
}
 
Example #22
Source File: AtlasClassificationDefStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.preDeleteByName({})", name);
    }

    AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);

    if (AtlasGraphUtilsV1.typeHasInstanceVertex(name)) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, name);
    }

    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }

    typeDefStore.deleteTypeVertexOutEdges(ret);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.preDeleteByName({}): ret=", name, ret);
    }

    return ret;
}
 
Example #23
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public AtlasEntityWithExtInfo getById(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getById({})", guid);
    }

    EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry);

    AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(guid);

    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getById({}): {}", guid, ret);
    }

    return ret;
}
 
Example #24
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    AtlasErrorCode             errorCode   = null;

    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_ATTRIBUTE_INVALID_TYPE,
            "expected invalid constraint failure - missing refAttribute");
}
 
Example #25
Source File: EntityREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
@POST
@Path("/uniqueAttribute/type/{typeName}/labels")
public void setLabels(@PathParam("typeName") String typeName, Set<String> labels,
                      @Context HttpServletRequest servletRequest) throws AtlasBaseException {

    Servlets.validateQueryParamLength("typeName", typeName);
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.setLabels(" + typeName + ")");
        }

        AtlasEntityType     entityType = ensureEntityType(typeName);
        Map<String, Object> attributes = getAttributes(servletRequest);
        String              guid       = entitiesStore.getGuidByUniqueAttributes(entityType, attributes);

        if (guid == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, attributes.toString());
        }

        entitiesStore.setLabels(guid, labels);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #26
Source File: EntityLineageService.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public AtlasLineageInfo getAtlasLineageInfo(String guid, LineageDirection direction, int depth) throws AtlasBaseException {
    AtlasLineageInfo lineageInfo;

    if (!entityExists(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }

    if (direction != null) {
        if (direction.equals(LineageDirection.INPUT)) {
            lineageInfo = getLineageInfo(guid, LineageDirection.INPUT, depth);
        } else if (direction.equals(LineageDirection.OUTPUT)) {
            lineageInfo = getLineageInfo(guid, LineageDirection.OUTPUT, depth);
        } else if (direction.equals(LineageDirection.BOTH)) {
            lineageInfo = getBothLineageInfo(guid, depth);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", direction.toString());
        }
    } else {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", null);
    }

    return lineageInfo;
}
 
Example #27
Source File: SearchContext.java    From atlas with Apache License 2.0 5 votes vote down vote up
private Set<AtlasEntityType> getEntityTypes(String typeName) throws AtlasBaseException {

        Set<AtlasEntityType> entityTypes = null;
        //split multiple typeNames by comma
        if (StringUtils.isNotEmpty(typeName)) {

            String[] types        = typeName.split(TYPENAME_DELIMITER);
            Set<String> typeNames = new HashSet<>(Arrays.asList(types));
            entityTypes           = typeNames.stream().map(n ->
                                    getEntityType(n)).filter(Objects::nonNull).collect(Collectors.toSet());

            // Validate if the type name is incorrect
            if (CollectionUtils.isEmpty(entityTypes) || entityTypes.size() != typeNames.size()) {
                if (CollectionUtils.isNotEmpty(entityTypes)) {
                    Set<String> validEntityTypes = new HashSet<>();
                    for (AtlasEntityType entityType : entityTypes) {
                        String name = entityType.getTypeName();
                        if (name.equals(MATCH_ALL_ENTITY_TYPES.getTypeName())) {
                            validEntityTypes.add(ALL_ENTITY_TYPES);
                            continue;
                        }
                        validEntityTypes.add(entityType.getTypeName());
                    }

                    typeNames.removeAll(validEntityTypes);
                }

                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, String.join(TYPENAME_DELIMITER, typeNames));
            }

        }

        return entityTypes;
    }
 
Example #28
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public AtlasEnumDef getEnumDefByGuid(String guid) throws AtlasBaseException {
    AtlasEnumDef ret = typeRegistry.getEnumDefByGuid(guid);
    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    return ret;
}
 
Example #29
Source File: GlossaryService.java    From atlas with Apache License 2.0 5 votes vote down vote up
@GraphTransaction
public List<AtlasRelatedTermHeader> getGlossaryTermsHeaders(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
    if (Objects.isNull(glossaryGuid)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
    }

    if (DEBUG_ENABLED) {
        LOG.debug("==> GlossaryService.getGlossaryTermsHeaders({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
    }

    AtlasGlossary glossary = getGlossary(glossaryGuid);

    List<AtlasRelatedTermHeader> ret;
    if (CollectionUtils.isNotEmpty(glossary.getTerms())) {
        List<AtlasRelatedTermHeader> terms = new ArrayList<>(glossary.getTerms());
        if (sortOrder != null) {
            terms.sort((o1, o2) -> sortOrder == SortOrder.ASCENDING ?
                                           o1.getDisplayText().compareTo(o2.getDisplayText()) :
                                           o2.getDisplayText().compareTo(o1.getDisplayText()));
        }
        ret = new PaginationHelper<>(terms, offset, limit).getPaginatedList();
    } else {
        ret = Collections.emptyList();
    }

    if (DEBUG_ENABLED) {
        LOG.debug("<== GlossaryService.getGlossaryTermsHeaders() : {}", ret);
    }

    return ret;
}
 
Example #30
Source File: EntityDiscoveryService.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public AtlasUserSavedSearch getSavedSearchByName(String currentUser, String userName, String searchName) throws AtlasBaseException {
    try {
        if (StringUtils.isEmpty(userName)) {
            userName = currentUser;
        } else if (!StringUtils.equals(currentUser, userName)) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "invalid data");
        }

        return userProfileService.getSavedSearch(userName, searchName);
    } catch (AtlasBaseException e) {
        LOG.error("getSavedSearchByName({}, {})", userName, searchName, e);
        throw e;
    }
}