Search in sources :

Example 11 with Id

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

the class LineageResource method inputsGraph.

/**
 * Returns input lineage graph for the given entity id.
 * @param guid dataset entity id
 * @return
 */
@GET
@Path("{guid}/inputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public LineageResponse inputsGraph(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> LineageResource.inputsGraph({})", guid);
    }
    LineageResponse ret = new LineageResponse();
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.inputsGraph(" + guid + ")");
        }
        AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.INPUT, -1);
        ret.setRequestId(Servlets.getRequestId());
        ret.setResults(LineageUtils.toLineageStruct(lineageInfo, typeRegistry));
        return ret;
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e);
        throw e;
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== LineageResource.inputsGraph({})", guid);
        }
    }
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) LineageResponse(org.apache.atlas.v1.model.lineage.LineageResponse) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with Id

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

the class StormAtlasHook method createTopologyInstance.

private Referenceable createTopologyInstance(TopologyInfo topologyInfo, Map stormConf) {
    Referenceable topologyReferenceable = new Referenceable(StormDataTypes.STORM_TOPOLOGY.getName());
    topologyReferenceable.set("id", topologyInfo.get_id());
    topologyReferenceable.set(AtlasClient.NAME, topologyInfo.get_name());
    topologyReferenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, topologyInfo.get_name());
    String owner = topologyInfo.get_owner();
    if (StringUtils.isEmpty(owner)) {
        owner = ANONYMOUS_OWNER;
    }
    topologyReferenceable.set(AtlasClient.OWNER, owner);
    topologyReferenceable.set("startTime", new Date(System.currentTimeMillis()));
    topologyReferenceable.set(AtlasConstants.CLUSTER_NAME_ATTRIBUTE, getClusterName(stormConf));
    return topologyReferenceable;
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Date(java.util.Date)

Example 13 with Id

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

the class EntityJerseyResourceIT method testUTF8.

@Test
public void testUTF8() throws Exception {
    // Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType()
    String classType = randomString();
    String attrName = random();
    String attrValue = random();
    ClassTypeDefinition classTypeDefinition = TypesUtil.createClassTypeDef(classType, null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef(attrName, AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typesDef = new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), Collections.<TraitTypeDefinition>emptyList(), Collections.singletonList(classTypeDefinition));
    createType(typesDef);
    Referenceable instance = new Referenceable(classType);
    instance.set(attrName, attrValue);
    Id guid = createInstance(instance);
    ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
    Referenceable getReferenceable = AtlasType.fromV1Json(AtlasType.toJson(response.get(AtlasClient.DEFINITION)), Referenceable.class);
    Assert.assertEquals(getReferenceable.get(attrName), attrValue);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Example 14 with Id

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

the class EntityJerseyResourceIT method testAddProperty.

@Test
public void testAddProperty() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable referenceable = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(referenceable);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    // add property
    String description = "bar table - new desc";
    addProperty(guid, "description", description);
    ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
    Assert.assertNotNull(response);
    referenceable.set("description", description);
    // invalid property for the type
    try {
        addProperty(guid, "invalid_property", "bar table");
        Assert.fail("Expected AtlasServiceException");
    } catch (AtlasServiceException e) {
        Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
    }
    String currentTime = String.valueOf(new DateTime());
    // updating date attribute as string not supported in v2
    // addProperty(guid, "createTime", currentTime);
    response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
    Assert.assertNotNull(response);
    referenceable.set("createTime", currentTime);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 15 with Id

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

the class EntityJerseyResourceIT method testPartialUpdateByUniqueAttributes.

@Test
public void testPartialUpdateByUniqueAttributes() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id tableId = createInstance(hiveTableInstance);
    final String guid = tableId._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String colName = "col1" + randomString();
    final List<Referenceable> columns = new ArrayList<>();
    Map<String, Object> values = new HashMap<>();
    values.put(NAME, colName);
    values.put("comment", "col1 comment");
    values.put(QUALIFIED_NAME, "default.table.col1@" + colName);
    values.put("comment", "col1 comment");
    values.put("type", "string");
    values.put("owner", "user1");
    values.put("position", 0);
    values.put("description", "col1");
    // table is a required reference, can't be null
    values.put("table", tableId);
    Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
    columns.add(ref);
    // Update by unique attribute
    values.put("type", "int");
    ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
    columns.set(0, ref);
    Referenceable tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {

        {
            put("columns", columns);
        }
    });
    LOG.debug("Updating entity= {}", tableUpdated);
    EntityResult entityResult = atlasClientV1.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, (String) hiveTableInstance.get(QUALIFIED_NAME), tableUpdated);
    assertEquals(entityResult.getUpdateEntities().size(), 1);
    assertEquals(entityResult.getUpdateEntities().get(0), guid);
    Referenceable entity = atlasClientV1.getEntity(guid);
    List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
    Assert.assertTrue(refs.get(0).getValuesMap().equals(values));
    Assert.assertEquals(refs.get(0).get("type"), "int");
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

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