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);
}
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);
}
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);
}
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);
}
}
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));
}
}
Aggregations