Search in sources :

Example 21 with Referenceable

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

the class FalconHookIT method assertEntityIsRegistered.

private String assertEntityIsRegistered(final String typeName, final String property, final String value) throws Exception {
    waitFor(80000, new Predicate() {

        @Override
        public void evaluate() throws Exception {
            Referenceable entity = atlasClient.getEntity(typeName, property, value);
            assertNotNull(entity);
        }
    });
    Referenceable entity = atlasClient.getEntity(typeName, property, value);
    return entity.getId()._getId();
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) JAXBException(javax.xml.bind.JAXBException)

Example 22 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable 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 23 with Referenceable

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

the class EntityResource method getEntity.

private Referenceable getEntity(String guid) throws AtlasBaseException {
    AtlasEntityWithExtInfo entity = entitiesStore.getById(guid);
    Referenceable referenceable = restAdapters.getReferenceable(entity);
    return referenceable;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) Referenceable(org.apache.atlas.v1.model.instance.Referenceable)

Example 24 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable 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 25 with Referenceable

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

the class EntityResource method getEntityDefinition.

/**
 * Fetch the complete definition of an entity given its GUID.
 *
 * @param guid GUID for the entity
 */
@GET
@Path("{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getEntityDefinition(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.getEntityDefinition({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getEntityDefinition(" + guid + ")");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Fetching entity definition for guid={} ", guid);
        }
        guid = ParamChecker.notEmpty(guid, "guid cannot be null");
        Referenceable entity = getEntity(guid);
        Map<String, Object> response = new HashMap<>();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        Response.Status status = Response.Status.NOT_FOUND;
        if (entity != null) {
            response.put(AtlasClient.DEFINITION, entity);
            status = Response.Status.OK;
        } else {
            response.put(AtlasClient.ERROR, Servlets.escapeJsonString(String.format("An entity with GUID={%s} does not exist", guid)));
        }
        return Response.status(status).entity(AtlasJson.toV1Json(response)).build();
    } catch (IllegalArgumentException e) {
        LOG.error("Bad GUID={} ", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get instance definition for GUID {}", guid, e);
        throw toWebApplicationException(e);
    } catch (WebApplicationException e) {
        LOG.error("Unable to get instance definition for GUID {}", guid, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get instance definition for GUID {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.getEntityDefinition({})", guid);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)143 Test (org.testng.annotations.Test)64 Id (org.apache.atlas.v1.model.instance.Id)37 Struct (org.apache.atlas.v1.model.instance.Struct)23 ArrayList (java.util.ArrayList)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 HashMap (java.util.HashMap)12 List (java.util.List)10 AtlasException (org.apache.atlas.AtlasException)10 HookNotification (org.apache.atlas.model.notification.HookNotification)10 Map (java.util.Map)9 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)9 AtlasServiceException (org.apache.atlas.AtlasServiceException)8 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)8 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)7 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)5