Search in sources :

Example 1 with AtlasEntityStream

use of org.apache.atlas.repository.store.graph.v1.AtlasEntityStream in project atlas by apache.

the class BasicTestSetup method loadEmployeeDataset.

protected void loadEmployeeDataset() {
    if (!baseLoaded) {
        loadBaseModels();
    }
    // Define employee dataset types
    AtlasTypesDef employeeTypes = TestUtilsV2.defineDeptEmployeeTypes();
    try {
        typeDefStore.createTypesDef(employeeTypes);
    } catch (AtlasBaseException e) {
        fail("Employee Type setup is required");
    }
    // Define entities for department
    AtlasEntity.AtlasEntitiesWithExtInfo deptEg2 = TestUtilsV2.createDeptEg2();
    try {
        entityStore.createOrUpdate(new AtlasEntityStream(deptEg2), false);
    } catch (AtlasBaseException e) {
        fail("Employee entity setup should've passed");
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream)

Example 2 with AtlasEntityStream

use of org.apache.atlas.repository.store.graph.v1.AtlasEntityStream in project atlas by apache.

the class ExportServiceTest method setupSampleData.

@BeforeClass
public void setupSampleData() throws AtlasBaseException {
    entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier, graphMapper);
    ;
    AtlasTypesDef sampleTypes = TestUtilsV2.defineDeptEmployeeTypes();
    AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(sampleTypes, typeRegistry);
    if (!typesToCreate.isEmpty()) {
        typeDefStore.createTypesDef(typesToCreate);
    }
    AtlasEntity.AtlasEntitiesWithExtInfo hrDept = TestUtilsV2.createDeptEg2();
    AtlasEntityStream entityStream = new AtlasEntityStream(hrDept);
    entityStore.createOrUpdate(entityStream, false);
    LOG.debug("==> setupSampleData: ", AtlasEntity.dumpObjects(hrDept.getEntities(), null).toString());
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream) AtlasEntityStoreV1(org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with AtlasEntityStream

use of org.apache.atlas.repository.store.graph.v1.AtlasEntityStream in project atlas by apache.

the class DataAccess method save.

public <T extends AtlasBaseModelObject> T save(T obj) throws AtlasBaseException {
    DataTransferObject<T> dto = (DataTransferObject<T>) dtoRegistry.get(obj.getClass());
    AtlasEntityWithExtInfo entityWithExtInfo = dto.toEntityWithExtInfo(obj);
    EntityMutationResponse entityMutationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
    if (hasError(entityMutationResponse)) {
        throw new AtlasBaseException(AtlasErrorCode.DATA_ACCESS_SAVE_FAILED, obj.toString());
    }
    return this.load(obj);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream)

Example 4 with AtlasEntityStream

use of org.apache.atlas.repository.store.graph.v1.AtlasEntityStream in project 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 = AtlasType.fromV1Json(entityJson, Referenceable.class);
        // update referenceable with Id if not specified in payload
        Id updateId = updatedEntity.getId();
        if (updateId != null && !AtlasTypeUtil.isAssignedGuid(updateId.getId())) {
            updatedEntity.setId(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());
        }
        String 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 (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) AtlasException(org.apache.atlas.AtlasException) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) Id(org.apache.atlas.v1.model.instance.Id)

Example 5 with AtlasEntityStream

use of org.apache.atlas.repository.store.graph.v1.AtlasEntityStream 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

AtlasEntityStream (org.apache.atlas.repository.store.graph.v1.AtlasEntityStream)8 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)5 AtlasException (org.apache.atlas.AtlasException)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)4 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)4 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)3 HashMap (java.util.HashMap)2 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)2 AtlasEntityStoreV1 (org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1)2 Referenceable (org.apache.atlas.typesystem.Referenceable)2 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)2 Id (org.apache.atlas.typesystem.persistence.Id)2 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 Id (org.apache.atlas.v1.model.instance.Id)2 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 BeforeClass (org.testng.annotations.BeforeClass)2 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)1 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)1