Search in sources :

Example 36 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryTest method testConcurrentCalls.

@Test
public //In some cases of parallel APIs, the edge is added, but get edge by label doesn't return the edge. ATLAS-1104
void testConcurrentCalls() throws Exception {
    final HierarchicalTypeDefinition<ClassType> refType = createClassTypeDef(randomString(), ImmutableSet.<String>of());
    HierarchicalTypeDefinition<ClassType> type = createClassTypeDef(randomString(), ImmutableSet.<String>of(), new AttributeDefinition("ref", refType.typeName, Multiplicity.OPTIONAL, true, null));
    typeSystem.defineClassType(refType);
    typeSystem.defineClassType(type);
    String refId1 = createEntity(new Referenceable(refType.typeName)).get(0);
    String refId2 = createEntity(new Referenceable(refType.typeName)).get(0);
    final Referenceable instance1 = new Referenceable(type.typeName);
    instance1.set("ref", new Referenceable(refId1, refType.typeName, null));
    final Referenceable instance2 = new Referenceable(type.typeName);
    instance2.set("ref", new Referenceable(refId2, refType.typeName, null));
    ExecutorService executor = Executors.newFixedThreadPool(3);
    List<Future<Object>> futures = new ArrayList<>();
    futures.add(executor.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return createEntity(instance1).get(0);
        }
    }));
    futures.add(executor.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return createEntity(instance2).get(0);
        }
    }));
    futures.add(executor.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return discoveryService.searchByDSL(TestUtils.TABLE_TYPE, new QueryParams(10, 0));
        }
    }));
    String id1 = (String) futures.get(0).get();
    String id2 = (String) futures.get(1).get();
    futures.get(2).get();
    executor.shutdown();
    boolean validated1 = assertEdge(id1, type.typeName);
    boolean validated2 = assertEdge(id2, type.typeName);
    assertTrue(validated1 | validated2);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) Future(java.util.concurrent.Future) QueryParams(org.apache.atlas.query.QueryParams) ClassType(org.apache.atlas.typesystem.types.ClassType) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test)

Example 37 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryTest method testCreateEntityWithTwoNestingLevels.

@Test
public void testCreateEntityWithTwoNestingLevels() throws AtlasException {
    List<Referenceable> toVerify = new ArrayList<>();
    Referenceable dept = new Referenceable(TestUtils.DEPARTMENT_TYPE);
    toVerify.add(dept);
    dept.set(TestUtils.NAME, "test2");
    Referenceable wallace = new Referenceable(TestUtils.PERSON_TYPE);
    toVerify.add(wallace);
    wallace.set(TestUtils.NAME, "Wallace");
    wallace.set(TestUtils.DEPARTMENT_ATTR, dept);
    Referenceable wallaceComputer = new Referenceable(TestUtils.ASSET_TYPE);
    toVerify.add(wallaceComputer);
    wallaceComputer.set("name", "wallaceComputer");
    wallace.set(TestUtils.ASSETS_ATTR, ImmutableList.of(wallaceComputer));
    Referenceable jordan = new Referenceable(TestUtils.PERSON_TYPE);
    toVerify.add(jordan);
    jordan.set(TestUtils.NAME, "Jordan");
    jordan.set(TestUtils.DEPARTMENT_ATTR, dept);
    Referenceable jordanComputer = new Referenceable(TestUtils.ASSET_TYPE);
    toVerify.add(jordanComputer);
    jordanComputer.set("name", "jordanComputer");
    jordan.set(TestUtils.ASSETS_ATTR, ImmutableList.of(jordanComputer));
    dept.set(TestUtils.EMPLOYEES_ATTR, ImmutableList.of(wallace, jordan));
    Map<String, Referenceable> positions = new HashMap<>();
    final String JANITOR = "janitor";
    final String RECEPTIONIST = "receptionist";
    positions.put(JANITOR, wallace);
    positions.put(RECEPTIONIST, jordan);
    dept.set(TestUtils.POSITIONS_ATTR, positions);
    ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, TestUtils.DEPARTMENT_TYPE);
    ITypedReferenceableInstance deptInstance = deptType.convert(dept, Multiplicity.REQUIRED);
    CreateUpdateEntitiesResult result = repositoryService.createEntities(deptInstance);
    validateGuidMapping(toVerify, result);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 38 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method testDeleteEntityWithTraits.

@Test
public void testDeleteEntityWithTraits() throws Exception {
    Referenceable entity = createDBEntity();
    String id = createInstance(entity);
    TraitType dataType = typeSystem.getDataType(TraitType.class, PII);
    ITypedStruct trait = dataType.convert(new Struct(TestUtils.PII), Multiplicity.REQUIRED);
    repositoryService.addTrait(id, trait);
    ITypedReferenceableInstance instance = repositoryService.getEntityDefinition(id);
    assertTrue(instance.getTraits().contains(PII));
    deleteEntities(id);
    assertEntityDeleted(id);
    assertTestDeleteEntityWithTraits(id);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 39 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryTest method validateGuidMapping.

private void validateGuidMapping(List<Referenceable> toVerify, CreateUpdateEntitiesResult result) throws AtlasException {
    Map<String, String> guids = result.getGuidMapping().getGuidAssignments();
    TestUtils.assertContentsSame(result.getCreatedEntities(), guids.values());
    assertEquals(guids.size(), toVerify.size());
    for (Referenceable r : toVerify) {
        loadAndDoSimpleValidation(guids.get(r.getId()._getId()), r);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable)

Example 40 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class EntityResource method partialUpdateEntityByGuid.

private Response partialUpdateEntityByGuid(String guid, HttpServletRequest request) {
    String entityJson = null;
    try {
        guid = ParamChecker.notEmpty(guid, "Guid property cannot be null");
        entityJson = Servlets.getRequestPayload(request);
        if (LOG.isDebugEnabled()) {
            LOG.debug("partially updating entity for guid {} : {} ", guid, entityJson);
        }
        Referenceable updatedEntity = InstanceSerialization.fromJsonReferenceable(entityJson, true);
        // update referenceable with Id if not specified in payload
        Id updateId = updatedEntity.getId();
        if (updateId != null && !updateId.isAssigned()) {
            updatedEntity.replaceWithNewId(new Id(guid, 0, updatedEntity.getTypeName()));
        }
        AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntity(updatedEntity);
        EntityMutationResponse mutationResponse = entitiesStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), true);
        CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Updated entities: {}", result.getEntityResult());
        }
        JSONObject response = getResponse(result);
        return Response.ok(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
        throw toWebApplicationException(e);
    } catch (EntityNotFoundException e) {
        LOG.error("An entity with GUID={} does not exist {} ", guid, entityJson, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    } catch (AtlasException | IllegalArgumentException e) {
        LOG.error("Unable to update entity by GUID {} {}", guid, entityJson, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    }
}
Also used : EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasException(org.apache.atlas.AtlasException) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.typesystem.Referenceable) JSONObject(org.codehaus.jettison.json.JSONObject) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) Id(org.apache.atlas.typesystem.persistence.Id)

Aggregations

Referenceable (org.apache.atlas.typesystem.Referenceable)235 Test (org.testng.annotations.Test)114 Id (org.apache.atlas.typesystem.persistence.Id)50 ArrayList (java.util.ArrayList)45 List (java.util.List)25 Struct (org.apache.atlas.typesystem.Struct)25 HashMap (java.util.HashMap)24 BeforeTest (org.testng.annotations.BeforeTest)24 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)22 AfterTest (org.testng.annotations.AfterTest)22 HookNotification (org.apache.atlas.notification.hook.HookNotification)20 IStruct (org.apache.atlas.typesystem.IStruct)18 ClassType (org.apache.atlas.typesystem.types.ClassType)16 JSONObject (org.codehaus.jettison.json.JSONObject)16 ImmutableList (com.google.common.collect.ImmutableList)15 AtlasServiceException (org.apache.atlas.AtlasServiceException)14 TraitType (org.apache.atlas.typesystem.types.TraitType)12 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)12 Date (java.util.Date)11 AtlasException (org.apache.atlas.AtlasException)11