org.apache.atlas.exception.AtlasBaseException Java Examples

The following examples show how to use org.apache.atlas.exception.AtlasBaseException. 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: AtlasEntityTestBase.java    From atlas with Apache License 2.0 6 votes vote down vote up
protected void validateEntity(AtlasEntityExtInfo entityExtInfo, AtlasStruct actual, AtlasStruct expected) throws AtlasBaseException, AtlasException {
    if (expected == null) {
        Assert.assertNull(actual, "expected null instance. Found " + actual);

        return;
    }

    Assert.assertNotNull(actual, "found null instance");

    AtlasStructType entityType = (AtlasStructType) typeRegistry.getType(actual.getTypeName());
    for (String attrName : expected.getAttributes().keySet()) {
        Object expectedVal = expected.getAttribute(attrName);
        Object actualVal   = actual.getAttribute(attrName);

        AtlasType attrType = entityType.getAttributeType(attrName);
        validateAttribute(entityExtInfo, actualVal, expectedVal, attrType, attrName);
    }
}
 
Example #2
Source File: SoftReferenceTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test(dependsOnMethods = "typeCreationFromFile")
public void entityCreationUsingSoftRef() throws IOException, AtlasBaseException {
    final int EXPECTED_ENTITY_COUNT = 6;
    AtlasEntity.AtlasEntityWithExtInfo dbEntity = AtlasType.fromJson(
            TestResourceFileUtils.getJson(RDBMS_DB_FILE), AtlasEntity.AtlasEntityWithExtInfo.class);

    EntityMutationResponse  response = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);

    assertNotNull(response);
    assertTrue(response.getCreatedEntities().size() == EXPECTED_ENTITY_COUNT);
    assertGraphStructure(response.getCreatedEntities().get(0).getGuid(),
            response.getCreatedEntities().get(1).getGuid(), RDBMS_SD_PROPERTY);

    dbGuid = response.getCreatedEntities().get(0).getGuid();
    storageGuid = response.getCreatedEntities().get(1).getGuid();
}
 
Example #3
Source File: EntityAuditListenerV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void onClassificationsDeleted(AtlasEntity entity, List<AtlasClassification> classifications) throws AtlasBaseException {
    if (CollectionUtils.isNotEmpty(classifications)) {
        MetricRecorder metric = RequestContext.get().startMetricRecord("entityAudit");

        List<EntityAuditEventV2> events = new ArrayList<>();

        for (AtlasClassification classification : classifications) {
            if (StringUtils.equals(entity.getGuid(), classification.getEntityGuid())) {
                events.add(createEvent(entity, CLASSIFICATION_DELETE, "Deleted classification: " + classification.getTypeName()));
            } else {
                events.add(createEvent(entity, PROPAGATED_CLASSIFICATION_DELETE, "Deleted propagated classification: " + classification.getTypeName()));
            }
        }

        auditRepository.putEventsV2(events);

        RequestContext.get().endMetricRecord(metric);
    }
}
 
Example #4
Source File: ExportImportAuditServiceTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void saveLogEntry() throws AtlasBaseException {
    final String source1 = "clx";
    final String target1 = "cly";
    ExportImportAuditEntry entry = saveAndGet(source1, ExportImportAuditEntry.OPERATION_EXPORT, target1);

    String source2 = "clx2";
    String target2 = "clx1";
    ExportImportAuditEntry entry2 = saveAndGet(source2, ExportImportAuditEntry.OPERATION_EXPORT, target2);

    pauseForIndexCreation();
    ExportImportAuditEntry actualEntry = retrieveEntry(entry);
    ExportImportAuditEntry actualEntry2 = retrieveEntry(entry2);

    assertNotEquals(actualEntry.getGuid(), actualEntry2.getGuid());
    assertNotNull(actualEntry.getGuid());
    assertEquals(actualEntry.getSourceServerName(), entry.getSourceServerName());
    assertEquals(actualEntry.getTargetServerName(), entry.getTargetServerName());
    assertEquals(actualEntry.getOperation(), entry.getOperation());
}
 
Example #5
Source File: GlossaryREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Get all terms associated with the specific category
 * @param categoryGuid unique identifier for glossary category
 * @param limit page size - by default there is no paging
 * @param offset offset for pagination purpose
 * @param sort ASC (default) or DESC
 * @return List of associated terms
 * @throws AtlasBaseException
 * @HTTP 200 List of terms for the given category or an empty list
 * @HTTP 404 If glossary category guid in invalid
 */
@GET
@Path("/category/{categoryGuid}/terms")
public List<AtlasRelatedTermHeader> getCategoryTerms(@PathParam("categoryGuid") String categoryGuid,
                                                     @DefaultValue("-1") @QueryParam("limit") String limit,
                                                     @DefaultValue("0") @QueryParam("offset") String offset,
                                                     @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException {
    Servlets.validateQueryParamLength("categoryGuid", categoryGuid);

    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getCategoryTerms(" + categoryGuid + ")");
        }

        return glossaryService.getCategoryTerms(categoryGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort));

    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #6
Source File: GlossaryREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Get all entity headers assigned with the specified term
 * @param termGuid GUID of the term
 * @param limit page size - by default there is no paging
 * @param offset offset for pagination purpose
 * @param sort ASC (default) or DESC
 * @return
 * @throws AtlasBaseException
 * @HTTP 200 List of entity headers (if any) for the given glossary or an empty list
 * @HTTP 404 If glossary term guid in invalid
 */
@GET
@Path("/terms/{termGuid}/assignedEntities")
public List<AtlasRelatedObjectId> getEntitiesAssignedWithTerm(@PathParam("termGuid") String termGuid,
                                                              @DefaultValue("-1") @QueryParam("limit") String limit,
                                                              @DefaultValue("0") @QueryParam("offset") String offset,
                                                              @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException {
    Servlets.validateQueryParamLength("termGuid", termGuid);

    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getEntitiesAssignedWithTerm(" + termGuid + ")");
        }

        return glossaryService.getAssignedEntities(termGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort));

    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #7
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Delete an entity identified by its GUID.
 * @param  guid GUID for the entity
 * @return EntityMutationResponse
 */
@DELETE
@Path("/guid/{guid}")
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse deleteByGuid(@PathParam("guid") final String guid) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

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

        return entitiesStore.deleteById(guid);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #8
Source File: EntityREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Set labels to a given entity
 * @param guid - Unique entity identifier
 * @param labels - set of labels to be set to the entity
 * @throws AtlasBaseException
 */
@POST
@Path("/guid/{guid}/labels")
@Produces(Servlets.JSON_MEDIA_TYPE)
@Consumes(Servlets.JSON_MEDIA_TYPE)
public void setLabels(@PathParam("guid") final String guid, Set<String> labels) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

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

        entitiesStore.setLabels(guid, labels);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #9
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private static List<AtlasClassificationDef> toAtlasClassificationDefs(List<HierarchicalTypeDefinition<TraitType>> traitTypeDefinitions)
        throws AtlasBaseException {
    List<AtlasClassificationDef> ret = new ArrayList<AtlasClassificationDef>();

    for (HierarchicalTypeDefinition<TraitType> traitType : traitTypeDefinitions) {
        AtlasClassificationDef  classifDef = new AtlasClassificationDef();
        List<AtlasAttributeDef> attrDefs   = new ArrayList<AtlasAttributeDef>();

        classifDef.setName(traitType.typeName);
        classifDef.setDescription(traitType.typeDescription);
        classifDef.setTypeVersion(traitType.typeVersion);
        classifDef.setSuperTypes(traitType.superTypes);

        AttributeDefinition[] attrDefinitions = traitType.attributeDefinitions;
        for (AttributeDefinition attrDefinition : attrDefinitions) {
            attrDefs.add(toAtlasAttributeDef(attrDefinition));
        }

        classifDef.setAttributeDefs(attrDefs);
        ret.add(classifDef);
    }

    return ret;
}
 
Example #10
Source File: EntityAuditListenerV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void onClassificationsAdded(AtlasEntity entity, List<AtlasClassification> classifications) throws AtlasBaseException {
    if (CollectionUtils.isNotEmpty(classifications)) {
        MetricRecorder metric = RequestContext.get().startMetricRecord("entityAudit");

        List<EntityAuditEventV2> events = new ArrayList<>();

        for (AtlasClassification classification : classifications) {
            if (entity.getGuid().equals(classification.getEntityGuid())) {
                events.add(createEvent(entity, CLASSIFICATION_ADD, "Added classification: " + AtlasType.toJson(classification)));
            } else {
                events.add(createEvent(entity, PROPAGATED_CLASSIFICATION_ADD, "Added propagated classification: " + AtlasType.toJson(classification)));
            }
        }

        auditRepository.putEventsV2(events);

        RequestContext.get().endMetricRecord(metric);
    }
}
 
Example #11
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 #12
Source File: AtlasJanusGraph.java    From atlas with Apache License 2.0 6 votes vote down vote up
private Object executeGremlinScript(String gremlinQuery) throws AtlasBaseException {
    GremlinGroovyScriptEngine scriptEngine = getGremlinScriptEngine();

    try {
        Bindings bindings = scriptEngine.createBindings();

        bindings.put("graph", getGraph());
        bindings.put("g", getGraph().traversal());

        Object result = scriptEngine.eval(gremlinQuery, bindings);

        return result;
    } catch (ScriptException e) {
        throw new AtlasBaseException(AtlasErrorCode.GREMLIN_SCRIPT_EXECUTION_FAILED, e, gremlinQuery);
    } finally {
        releaseGremlinScriptEngine(scriptEngine);
    }
}
 
Example #13
Source File: AtlasRelationshipStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public AtlasRelationship create(AtlasRelationship relationship) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> create({})", relationship);
    }

    AtlasVertex end1Vertex = getVertexFromEndPoint(relationship.getEnd1());
    AtlasVertex end2Vertex = getVertexFromEndPoint(relationship.getEnd2());

    AtlasEdge edge = createRelationship(end1Vertex, end2Vertex, relationship);

    AtlasRelationship ret = edge != null ? entityRetriever.mapEdgeToAtlasRelationship(edge) : null;

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

    return ret;
}
 
Example #14
Source File: AtlasClassificationDefStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public List<AtlasClassificationDef> getAll() throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.getAll()");
    }

    List<AtlasClassificationDef> ret = new ArrayList<>();

    Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.TRAIT);
    while (vertices.hasNext()) {
        ret.add(toClassificationDef(vertices.next()));
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.getAll(): count={}", ret.size());
    }
    return ret;
}
 
Example #15
Source File: EntityAuditListenerV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void onBusinessAttributesUpdated(AtlasEntity entity, Map<String, Map<String, Object>> updatedBusinessAttributes) throws AtlasBaseException {
    if (MapUtils.isNotEmpty(updatedBusinessAttributes)) {
        MetricRecorder metric = RequestContext.get().startMetricRecord("entityAudit");

        List<EntityAuditEventV2> auditEvents = new ArrayList<>();

        for (Map.Entry<String, Map<String, Object>> entry : updatedBusinessAttributes.entrySet()) {
            String              bmName     = entry.getKey();
            Map<String, Object> attributes = entry.getValue();
            String              details    = AtlasJson.toJson(new AtlasStruct(bmName, attributes));
            EntityAuditEventV2  auditEvent = createEvent(entity, BUSINESS_ATTRIBUTE_UPDATE, "Updated business attributes: " + details);

            auditEvents.add(auditEvent);
        }

        auditRepository.putEventsV2(auditEvents);

        RequestContext.get().endMetricRecord(metric);
    }
}
 
Example #16
Source File: TypesREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Bulk update API for all types, changes detected in the type definitions would be persisted
 * @param typesDef A composite object that captures all type definition changes
 * @return A composite object with lists of type definitions that were updated
 * @throws Exception
 * @HTTP 200 On successful update of requested type definitions
 * @HTTP 400 On validation failure for any type definitions
 */
@PUT
@Path("/typedefs")
@Experimental
public AtlasTypesDef updateAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesREST.updateAtlasTypeDefs(" +
                                                           AtlasTypeUtil.toDebugString(typesDef) + ")");
        }

        return typeDefStore.updateTypesDef(typesDef);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #17
Source File: AtlasEntityDefStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public AtlasEntityDef create(AtlasEntityDef entityDef, AtlasVertex preCreateResult) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEntityDefStoreV1.create({}, {})", entityDef, preCreateResult);
    }

    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, entityDef), "create entity-def ", entityDef.getName());

    AtlasVertex vertex = (preCreateResult == null) ? preCreate(entityDef) : preCreateResult;

    updateVertexAddReferences(entityDef, vertex);

    AtlasEntityDef ret = toEntityDef(vertex);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEntityDefStoreV1.create({}, {}): {}", entityDef, preCreateResult, ret);
    }

    return ret;
}
 
Example #18
Source File: AuditsWriter.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void add(String userName, AtlasImportResult result,
                long startTime, long endTime,
                List<String> entityGuids) throws AtlasBaseException {
    request = result.getRequest();
    replicationOptionState = request.isReplicationOptionSet();

    saveCurrentServer();

    sourceServerFullName = request.getOptionKeyReplicatedFrom();
    sourceServerName = getServerNameFromFullName(sourceServerFullName);
    auditService.add(userName,
            sourceServerName, getCurrentClusterName(),
            ExportImportAuditEntry.OPERATION_IMPORT,
            AtlasType.toJson(result), startTime, endTime, !entityGuids.isEmpty());

    if(result.getOperationStatus() == AtlasImportResult.OperationStatus.FAIL) {
        return;
    }

    updateReplicationAttribute(replicationOptionState, sourceServerName, sourceServerFullName, entityGuids,
            Constants.ATTR_NAME_REPLICATED_FROM, result.getExportResult().getChangeMarker());
}
 
Example #19
Source File: ExportServiceTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void verifyExportForFullEmployeeData(ZipSource zipSource) throws AtlasBaseException {
    final List<String> expectedEntityTypes = Arrays.asList(new String[]{"Manager", "Employee", "Department"});

    assertNotNull(zipSource.getCreationOrder());
    assertTrue(zipSource.hasNext());

    while (zipSource.hasNext()) {
        AtlasEntity entity = zipSource.next();

        assertNotNull(entity);
        assertEquals(AtlasEntity.Status.ACTIVE, entity.getStatus());
        assertTrue(expectedEntityTypes.contains(entity.getTypeName()));
    }

    verifyTypeDefs(zipSource);
}
 
Example #20
Source File: DeleteHandlerV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Delete all traits from the specified vertex.
 * @param instanceVertex
 * @throws AtlasException
 */
private void deleteAllTraits(AtlasVertex instanceVertex) throws AtlasBaseException {
    List<String> traitNames = GraphHelper.getTraitNames(instanceVertex);
    LOG.debug("Deleting traits {} for {}", traitNames, string(instanceVertex));
    String typeName = GraphHelper.getTypeName(instanceVertex);

    for (String traitNameToBeDeleted : traitNames) {
        String relationshipLabel = GraphHelper.getTraitLabel(typeName, traitNameToBeDeleted);
        deleteEdgeReference(instanceVertex, relationshipLabel, TypeCategory.CLASSIFICATION, false);
    }
}
 
Example #21
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public AtlasStructDef getStructDefByName(String name) throws AtlasBaseException {
    AtlasStructDef ret = typeRegistry.getStructDefByName(name);

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

    return ret;
}
 
Example #22
Source File: AtlasEntityChangeNotifier.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyPropagatedEntities() throws AtlasBaseException {
    RequestContext                         context             = RequestContext.get();
    Map<String, List<AtlasClassification>> addedPropagations   = context.getAddedPropagations();
    Map<String, List<AtlasClassification>> removedPropagations = context.getRemovedPropagations();

    notifyPropagatedEntities(addedPropagations, PROPAGATED_CLASSIFICATION_ADD);
    notifyPropagatedEntities(removedPropagations, PROPAGATED_CLASSIFICATION_DELETE);
}
 
Example #23
Source File: AtlasEntityStoreV2Test.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test (dependsOnMethods = "updateCustomAttributesToEntity")
public void deleteCustomAttributesToEntity() throws AtlasBaseException {
    AtlasEntity         tblEntity             = getEntityFromStore(tblEntityGuid);
    Map<String, String> emptyCustomAttributes = new HashMap<>();

    // remove all custom attributes
    tblEntity.setCustomAttributes(emptyCustomAttributes);

    entityStore.createOrUpdate(new AtlasEntityStream(tblEntity), false);

    tblEntity = getEntityFromStore(tblEntityGuid);

    assertEquals(emptyCustomAttributes, tblEntity.getCustomAttributes());
}
 
Example #24
Source File: AtlasTypeDefGraphStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
void deleteTypeVertex(AtlasVertex vertex) throws AtlasBaseException {
    Iterator<AtlasEdge> inEdges = vertex.getEdges(AtlasEdgeDirection.IN).iterator();

    if (inEdges.hasNext()) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES);
    }

    Iterable<AtlasEdge> edges = vertex.getEdges(AtlasEdgeDirection.OUT);

    for (AtlasEdge edge : edges) {
        atlasGraph.removeEdge(edge);
    }
    atlasGraph.removeVertex(vertex);
}
 
Example #25
Source File: AtlasTypeDefGraphStoreTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testUpdate"}, dataProvider = "allCreatedTypes")
public void testDelete(AtlasTypesDef atlasTypesDef){
    try {
        typeDefStore.deleteTypesDef(atlasTypesDef);
    } catch (AtlasBaseException e) {
        fail("Deletion should've succeeded");
    }
}
 
Example #26
Source File: ZipSinkTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyExportOrderEntryName_verifies() throws AtlasBaseException, IOException {

    ZipInputStream zis = getZipInputStreamForDefaultExportOrder();
    ZipEntry ze = zis.getNextEntry();

    assertEquals(ze.getName().replace(".json", ""), ZipExportFileNames.ATLAS_EXPORT_ORDER_NAME.toString());
}
 
Example #27
Source File: EntityGraphRetriever.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasVertex getEntityVertex(String guid) throws AtlasBaseException {
    AtlasVertex ret = AtlasGraphUtilsV2.findByGuid(this.graph, guid);

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

    return ret;
}
 
Example #28
Source File: AtlasTypeRegistry.java    From atlas with Apache License 2.0 5 votes vote down vote up
AtlasTransientTypeRegistry lockTypeRegistryForUpdate(int lockMaxWaitTimeInSeconds) throws AtlasBaseException {
    LOG.debug("==> lockTypeRegistryForUpdate()");

    boolean alreadyLockedByCurrentThread = typeRegistryUpdateLock.isHeldByCurrentThread();

    if (!alreadyLockedByCurrentThread) {
        if (lockedByThread != null) {
            LOG.info("lockTypeRegistryForUpdate(): waiting for lock to be released by thread {}", lockedByThread);
        }
    } else {
        LOG.warn("lockTypeRegistryForUpdate(): already locked. currentLockCount={}",
                typeRegistryUpdateLock.getHoldCount());
    }

    try {
        boolean isLocked = typeRegistryUpdateLock.tryLock(lockMaxWaitTimeInSeconds, TimeUnit.SECONDS);

        if (!isLocked) {
            throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK);
        }
    } catch (InterruptedException excp) {
        throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK, excp);
    }

    if (!alreadyLockedByCurrentThread) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("lockTypeRegistryForUpdate(): wait over..got the lock");
        }

        typeRegistryUnderUpdate = new AtlasTransientTypeRegistry(typeRegistry);
        lockedByThread          = Thread.currentThread().getName();
    }

    LOG.debug("<== lockTypeRegistryForUpdate()");

    return typeRegistryUnderUpdate;
}
 
Example #29
Source File: BasicSearchClassificationTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void searchByTagAndTagFilters() throws AtlasBaseException {
    SearchParameters params = new SearchParameters();
    params.setClassification(DIMENSIONAL_CLASSIFICATION);
    FilterCriteria filterCriteria = getSingleFilterCondition("attr1", Operator.EQ, "Test");
    params.setTagFilters(filterCriteria);

    List<AtlasEntityHeader> entityHeaders = discoveryService.searchWithParameters(params).getEntities();

    assertEquals(entityHeaders.size(), 1);
    assertEquals(entityHeaders.get(0).getGuid(), dimensionalTagGuid);

}
 
Example #30
Source File: PathTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void migrationImport() throws IOException, AtlasBaseException {
    final int EXPECTED_TOTAL_COUNT = 92;

    runFileImporter("path_db");

    AtlasVertex v = assertHdfsPathVertices(1);
    assertVertexProperties(v);
    assertMigrationStatus(EXPECTED_TOTAL_COUNT);
}