Search in sources :

Example 1 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class AuditRepositoryTestBase method testListPagination.

@Test
public void testListPagination() throws Exception {
    String id1 = "id1" + rand();
    String id2 = "id2" + rand();
    String id3 = "id3" + rand();
    long ts = System.currentTimeMillis();
    Referenceable entity = new Referenceable(rand());
    List<EntityAuditEvent> expectedEvents = new ArrayList<>(3);
    for (int i = 0; i < 3; i++) {
        // Add events for both ids
        EntityAuditEvent event = new EntityAuditEvent(id2, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.ENTITY_UPDATE, "details" + i, entity);
        eventRepository.putEventsV1(event);
        expectedEvents.add(event);
        eventRepository.putEventsV1(new EntityAuditEvent(id1, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.TAG_DELETE, "details" + i, entity));
        eventRepository.putEventsV1(new EntityAuditEvent(id3, ts - i, "user" + i, EntityAuditEvent.EntityAuditAction.TAG_ADD, "details" + i, entity));
    }
    // Use ts for which there is no event - ts + 2
    List<EntityAuditEvent> events = eventRepository.listEventsV1(id2, null, (short) 3);
    assertEquals(events.size(), 3);
    assertEventEquals(events.get(0), expectedEvents.get(0));
    assertEventEquals(events.get(1), expectedEvents.get(1));
    assertEventEquals(events.get(2), expectedEvents.get(2));
    // Use last event's timestamp for next list(). Should give only 1 event and shouldn't include events from other id
    events = eventRepository.listEventsV1(id2, events.get(2).getEventKey(), (short) 3);
    assertEquals(events.size(), 1);
    assertEventEquals(events.get(0), expectedEvents.get(2));
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ArrayList(java.util.ArrayList) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 2 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class AtlasObjectIdConverter method fromV1ToV2.

@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, AtlasFormatConverter.ConverterContext converterContext) throws AtlasBaseException {
    Object ret = null;
    if (v1Obj != null) {
        if (v1Obj instanceof Id) {
            Id id = (Id) v1Obj;
            ret = new AtlasObjectId(id.getId(), id.getTypeName());
        } else if (v1Obj instanceof Referenceable) {
            Referenceable refInst = (Referenceable) v1Obj;
            String guid = refInst.getId().getId();
            ret = new AtlasObjectId(guid, refInst.getTypeName());
            if (!converterContext.entityExists(guid) && hasAnyAssignedAttribute(refInst)) {
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(refInst.getTypeName());
                AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
                AtlasEntity entity = converter.fromV1ToV2(v1Obj, entityType, converterContext);
                converterContext.addReferredEntity(entity);
            }
        }
    }
    return ret;
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.v1.model.instance.Id) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 3 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class AtlasObjectIdConverter method fromV2ToV1.

@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    Id ret = null;
    if (v2Obj != null) {
        if (v2Obj instanceof Map) {
            Map v2Map = (Map) v2Obj;
            String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
            String typeName = (String) v2Map.get(AtlasObjectId.KEY_TYPENAME);
            if (StringUtils.isEmpty(idStr)) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
            }
            ret = new Id(idStr, 0, typeName);
        } else if (v2Obj instanceof AtlasObjectId) {
            // transient-id
            AtlasObjectId objId = (AtlasObjectId) v2Obj;
            ret = new Id(objId.getGuid(), 0, objId.getTypeName());
        } else if (v2Obj instanceof AtlasEntity) {
            AtlasEntity entity = (AtlasEntity) v2Obj;
            ret = new Id(entity.getGuid(), entity.getVersion() == null ? 0 : entity.getVersion().intValue(), entity.getTypeName());
        } else {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, type.getTypeCategory().name());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.v1.model.instance.Id) Map(java.util.Map)

Example 4 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class FalconHookIT method testCreateProcess.

@Test
public void testCreateProcess() throws Exception {
    Cluster cluster = loadEntity(EntityType.CLUSTER, CLUSTER_RESOURCE, "cluster" + random());
    STORE.publish(EntityType.CLUSTER, cluster);
    assertClusterIsRegistered(cluster);
    Feed infeed = getTableFeed(FEED_RESOURCE, cluster.getName(), null);
    String infeedId = atlasClient.getEntity(FalconDataTypes.FALCON_FEED.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, FalconBridge.getFeedQualifiedName(infeed.getName(), cluster.getName())).getId()._getId();
    Feed outfeed = getTableFeed(FEED_RESOURCE, cluster.getName());
    String outFeedId = atlasClient.getEntity(FalconDataTypes.FALCON_FEED.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, FalconBridge.getFeedQualifiedName(outfeed.getName(), cluster.getName())).getId()._getId();
    Process process = loadEntity(EntityType.PROCESS, PROCESS_RESOURCE, "process" + random());
    process.getClusters().getClusters().get(0).setName(cluster.getName());
    process.getInputs().getInputs().get(0).setFeed(infeed.getName());
    process.getOutputs().getOutputs().get(0).setFeed(outfeed.getName());
    STORE.publish(EntityType.PROCESS, process);
    String pid = assertProcessIsRegistered(process, cluster.getName());
    Referenceable processEntity = atlasClient.getEntity(pid);
    assertNotNull(processEntity);
    assertEquals(processEntity.get(AtlasClient.NAME), process.getName());
    assertEquals(((List<Id>) processEntity.get("inputs")).get(0)._getId(), infeedId);
    assertEquals(((List<Id>) processEntity.get("outputs")).get(0)._getId(), outFeedId);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Cluster(org.apache.falcon.entity.v0.cluster.Cluster) Process(org.apache.falcon.entity.v0.process.Process) List(java.util.List) Feed(org.apache.falcon.entity.v0.feed.Feed) Test(org.testng.annotations.Test)

Example 5 with Id

use of org.apache.atlas.v1.model.instance.Id 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)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)62 Test (org.testng.annotations.Test)39 Id (org.apache.atlas.v1.model.instance.Id)38 Struct (org.apache.atlas.v1.model.instance.Struct)15 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)11 List (java.util.List)7 AtlasException (org.apache.atlas.AtlasException)6 AtlasServiceException (org.apache.atlas.AtlasServiceException)6 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)5 HashMap (java.util.HashMap)4 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)4 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)4 Feed (org.apache.falcon.entity.v0.feed.Feed)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3