org.apache.atlas.v1.model.instance.Id Java Examples

The following examples show how to use org.apache.atlas.v1.model.instance.Id. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTraitNames() 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 id = createInstance(hiveTableInstance);

    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }

    List<String> traits = atlasClientV1.listTraits(guid);
    assertNotNull(traits);
    Assert.assertEquals(traits.size(), 7);
}
 
Example #2
Source File: DataSetLineageJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
Id table(String name, String description, Id dbId, String owner, String tableType, List<Referenceable> columns,
        String... traitNames) throws Exception {
    Referenceable referenceable = new Referenceable(HIVE_TABLE_TYPE, traitNames);
    referenceable.set("name", name);
    referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
    referenceable.set("description", description);
    referenceable.set("owner", owner);
    referenceable.set("tableType", tableType);
    referenceable.set("createTime", System.currentTimeMillis());
    referenceable.set("lastAccessTime", System.currentTimeMillis());
    referenceable.set("retention", System.currentTimeMillis());

    referenceable.set("db", dbId);
    referenceable.set("columns", columns);

    return createInstance(referenceable);
}
 
Example #3
Source File: DataSetLineageJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
Id loadProcess(String name, String user, List<Id> inputTables, List<Id> outputTables, String queryText,
        String queryPlan, String queryId, String queryGraph, String... traitNames) throws Exception {
    Referenceable referenceable = new Referenceable(HIVE_PROCESS_TYPE, traitNames);
    referenceable.set("name", name);
    referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
    referenceable.set("userName", user);
    referenceable.set("startTime", System.currentTimeMillis());
    referenceable.set("endTime", System.currentTimeMillis() + 10000);

    referenceable.set("inputs", inputTables);
    referenceable.set("outputs", outputTables);

    referenceable.set("operationType", "testOperation");
    referenceable.set("queryText", queryText);
    referenceable.set("queryPlan", queryPlan);
    referenceable.set("queryId", queryId);
    referenceable.set("queryGraph", queryGraph);

    return createInstance(referenceable);
}
 
Example #4
Source File: DataSetLineageJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutputsGraphForEntity() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
    ObjectNode results = atlasClientV1.getOutputGraphForEntity(tableId);
    Assert.assertNotNull(results);

    Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
    Map<String, Object> vertices = (Map<String, Object>) resultsInstance.get("vertices");
    Assert.assertEquals(vertices.size(), 3);

    Object verticesObject = vertices.get(tableId);
    Struct vertex         = null;

    if (verticesObject instanceof Map) {
        vertex  = new Struct ((Map)verticesObject);
    } else if (verticesObject instanceof Struct) {
        vertex = (Struct)verticesObject;
    }

    assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());

    Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
    Assert.assertEquals(edges.size(), 4);
}
 
Example #5
Source File: QuickStartIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessIsAdded() throws AtlasServiceException {
    Referenceable loadProcess = atlasClientV1.getEntity(QuickStart.LOAD_PROCESS_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
            QuickStart.LOAD_SALES_DAILY_PROCESS);

    assertEquals(QuickStart.LOAD_SALES_DAILY_PROCESS, loadProcess.get(AtlasClient.NAME));
    assertEquals(QuickStart.LOAD_SALES_DAILY_PROCESS_DESCRIPTION, loadProcess.get("description"));

    List<Id> inputs = (List<Id>)loadProcess.get(QuickStart.INPUTS_ATTRIBUTE);
    List<Id> outputs = (List<Id>)loadProcess.get(QuickStart.OUTPUTS_ATTRIBUTE);
    assertEquals(2, inputs.size());
    String salesFactTableId = getTableId(QuickStart.SALES_FACT_TABLE);
    String timeDimTableId = getTableId(QuickStart.TIME_DIM_TABLE);
    String salesFactDailyMVId = getTableId(QuickStart.SALES_FACT_DAILY_MV_TABLE);

    assertEquals(salesFactTableId, inputs.get(0)._getId());
    assertEquals(timeDimTableId, inputs.get(1)._getId());
    assertEquals(salesFactDailyMVId, outputs.get(0)._getId());
}
 
Example #6
Source File: EntityNotificationIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void testDeleteEntity() throws Exception {
    final String        tableName      = "table-" + randomString();
    final String        dbName         = "db-" + randomString();
    final Referenceable HiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    final Id            dbId           = createInstance(HiveDBInstance);
    final Referenceable tableInstance  = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    final Id            tableId        = createInstance(tableInstance);
    final String        guid           = tableId._getId();

    waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(OperationType.ENTITY_CREATE, HIVE_TABLE_TYPE_BUILTIN, guid));

    final String name = (String) tableInstance.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME);

    atlasClientV1.deleteEntity(HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);

    waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(OperationType.ENTITY_DELETE, HIVE_TABLE_TYPE_BUILTIN, guid));
}
 
Example #7
Source File: NotificationHookConsumerIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteByQualifiedName() throws Exception {
    final Referenceable entity        = new Referenceable(DATABASE_TYPE_BUILTIN);
    final String        dbName        = "db" + randomString();
    final String        clusterName   = randomString();
    final String        qualifiedName = dbName + "@" + clusterName;

    entity.set(NAME, dbName);
    entity.set(DESCRIPTION, randomString());
    entity.set(QUALIFIED_NAME, qualifiedName);
    entity.set(CLUSTER_NAME, clusterName);

    final String dbId = atlasClientV1.createEntity(entity).get(0);

    sendHookMessage(new EntityDeleteRequest(TEST_USER, DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, qualifiedName));

    waitFor(MAX_WAIT_TIME, new Predicate() {
        @Override
        public boolean evaluate() throws Exception {
            Referenceable getEntity = atlasClientV1.getEntity(dbId);

            return getEntity.getId().getState() == Id.EntityState.DELETED;
        }
    });
}
 
Example #8
Source File: EntityJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testUTF8() throws Exception {
    String              attrName            = randomUTF8();
    String              attrValue           = randomUTF8();
    String              classType           = randomString(); //Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType()
    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 entityToCreate  = new Referenceable(classType, Collections.singletonMap(attrName, attrValue));
    Id            guid            = createInstance(entityToCreate);
    ObjectNode    response        = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
    Object        objResponse     = response.get(AtlasClient.DEFINITION);
    String        jsonResponse    = AtlasType.toJson(objResponse);
    Referenceable createdEntity   = AtlasType.fromV1Json(jsonResponse, Referenceable.class);
    Object        entityAttrValue = createdEntity.get(attrName);

    Assert.assertEquals(entityAttrValue, attrValue,
                        "attrName=" + attrName + "; attrValue=" + attrValue + "; entityToCreate=" + entityToCreate + "; entityId=" + guid + "; getEntityResponse_Obj=" + objResponse + "; getEntityResponse_Json=" + jsonResponse + "; getEntityResponse_Entity=" + createdEntity);
}
 
Example #9
Source File: EntityJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = AtlasServiceException.class)
public void testDeleteTraitNonExistent() 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 id = createInstance(hiveTableInstance);

    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }

    final String traitName = "blah_trait";
    atlasClientV1.deleteTrait(guid, traitName);
    fail("trait=" + traitName + " should be defined in type system before it can be deleted");
}
 
Example #10
Source File: GraphHelper.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * For the given type, finds an unique attribute and checks if there is an existing instance with the same
 * unique value
 *
 * @param classType
 * @param instance
 * @return
 * @throws AtlasException
 */
public AtlasVertex getVertexForInstanceByUniqueAttribute(AtlasEntityType classType, Referenceable instance)
    throws AtlasException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking if there is an instance with the same unique attributes for instance {}", instance.toShortString());
    }

    AtlasVertex result = null;
    for (AtlasAttribute attributeInfo : classType.getUniqAttributes().values()) {
        String propertyKey = attributeInfo.getQualifiedName();
        try {
            result = findVertex(propertyKey, instance.get(attributeInfo.getName()),
                    ENTITY_TYPE_PROPERTY_KEY, classType.getTypeName(),
                    STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name());
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found vertex by unique attribute : {}={}", propertyKey, instance.get(attributeInfo.getName()));
            }
        } catch (EntityNotFoundException e) {
            //Its ok if there is no entity with the same unique value
        }
    }

    return result;
}
 
Example #11
Source File: AtlasJson.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Id id, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    if (id != null) {
        Map<String, Object> valueMap = new HashMap<>();

        valueMap.put(V1_KEY_ID, id._getId());
        valueMap.put(V1_KEY_$TYPENAME, id.getTypeName());
        valueMap.put(V1_KEY_VERSION, id.getVersion());

        if (id.getState() != null) {
            valueMap.put(V1_KEY_STATE, id.getState().toString());
        }

        jgen.writeObject(valueMap);
    }
}
 
Example #12
Source File: EntityJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEntityList() 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 id = createInstance(hiveTableInstance);

    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }

    List<String> entities = atlasClientV1.listEntities(HIVE_TABLE_TYPE_BUILTIN);
    Assert.assertNotNull(entities);
    Assert.assertTrue(entities.contains(guid));
}
 
Example #13
Source File: EntityJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEntityDefinition() 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 id = createInstance(hiveTableInstance);

    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }

    Referenceable entity = atlasClientV1.getEntity(guid);
    Assert.assertNotNull(entity);
}
 
Example #14
Source File: EntityJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void testAddNullProperty() 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 id = createInstance(hiveTableInstance);

    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }

    //add property
    addProperty(guid, null, "foo bar");
    Assert.fail();
}
 
Example #15
Source File: FalconHookIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
private TypesUtil.Pair<String, Feed> getHDFSFeed(String feedResource, String clusterName) throws Exception {
    Feed feed = loadEntity(EntityType.FEED, feedResource, "feed" + random());
    org.apache.falcon.entity.v0.feed.Cluster feedCluster = feed.getClusters().getClusters().get(0);
    feedCluster.setName(clusterName);
    STORE.publish(EntityType.FEED, feed);
    String feedId = assertFeedIsRegistered(feed, clusterName);
    assertFeedAttributes(feedId);

    String processId = assertEntityIsRegistered(FalconDataTypes.FALCON_FEED_CREATION.getName(),
            AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
            FalconBridge.getFeedQualifiedName(feed.getName(), clusterName));
    Referenceable processEntity = atlasClient.getEntity(processId);
    assertEquals(((List<Id>)processEntity.get("outputs")).get(0).getId(), feedId);

    String inputId = ((List<Id>) processEntity.get("inputs")).get(0).getId();
    Referenceable pathEntity = atlasClient.getEntity(inputId);
    assertEquals(pathEntity.getTypeName(), HiveMetaStoreBridge.HDFS_PATH);

    List<Location> locations = FeedHelper.getLocations(feedCluster, feed);
    Location dataLocation = FileSystemStorage.getLocation(locations, LocationType.DATA);
    assertEquals(pathEntity.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME),
            FalconBridge.normalize(dataLocation.getPath()));

    return TypesUtil.Pair.of(feedId, feed);
}
 
Example #16
Source File: EntityJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubmitEntity() 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);
    }
}
 
Example #17
Source File: FalconHookIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void verifyFeedLineage(String feedName, String clusterName, String feedId, String dbName, String tableName)
        throws Exception{
    //verify that lineage from hive table to falcon feed is created
    String processId = assertEntityIsRegistered(FalconDataTypes.FALCON_FEED_CREATION.getName(),
            AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
            FalconBridge.getFeedQualifiedName(feedName, clusterName));
    Referenceable processEntity = atlasClient.getEntity(processId);
    assertEquals(((List<Id>)processEntity.get("outputs")).get(0).getId(), feedId);

    String inputId = ((List<Id>) processEntity.get("inputs")).get(0).getId();
    Referenceable tableEntity = atlasClient.getEntity(inputId);
    assertEquals(tableEntity.getTypeName(), HiveDataTypes.HIVE_TABLE.getName());
    assertEquals(tableEntity.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME),
            HiveMetaStoreBridge.getTableQualifiedName(clusterName, dbName, tableName));

}
 
Example #18
Source File: FalconHookIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplicationFeed() throws Exception {
    Cluster srcCluster = loadEntity(EntityType.CLUSTER, CLUSTER_RESOURCE, "cluster" + random());
    STORE.publish(EntityType.CLUSTER, srcCluster);
    assertClusterIsRegistered(srcCluster);

    Cluster targetCluster = loadEntity(EntityType.CLUSTER, CLUSTER_RESOURCE, "cluster" + random());
    STORE.publish(EntityType.CLUSTER, targetCluster);
    assertClusterIsRegistered(targetCluster);

    Feed feed = getTableFeed(FEED_REPLICATION_RESOURCE, srcCluster.getName(), targetCluster.getName());
    String inId = atlasClient.getEntity(FalconDataTypes.FALCON_FEED.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
            FalconBridge.getFeedQualifiedName(feed.getName(), srcCluster.getName())).getId()._getId();
    String outId = atlasClient.getEntity(FalconDataTypes.FALCON_FEED.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
            FalconBridge.getFeedQualifiedName(feed.getName(), targetCluster.getName())).getId()._getId();


    String processId = assertEntityIsRegistered(FalconDataTypes.FALCON_FEED_REPLICATION.getName(),
            AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, feed.getName());
    Referenceable process = atlasClient.getEntity(processId);
    assertEquals(((List<Id>)process.get("inputs")).get(0)._getId(), inId);
    assertEquals(((List<Id>)process.get("outputs")).get(0)._getId(), outId);
}
 
Example #19
Source File: QuickStart.java    From atlas with Apache License 2.0 6 votes vote down vote up
Id table(String name, String description, Id dbId, Referenceable sd, String owner, String tableType,
        List<Referenceable> columns, String... traitNames) throws AtlasBaseException {
    try {
    Referenceable referenceable = new Referenceable(TABLE_TYPE, traitNames);
    referenceable.set("name", name);
    referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
    referenceable.set("description", description);
    referenceable.set("owner", owner);
    referenceable.set("tableType", tableType);
    referenceable.set("createTime", System.currentTimeMillis());
    referenceable.set("lastAccessTime", System.currentTimeMillis());
    referenceable.set("retention", System.currentTimeMillis());
    referenceable.set("db", dbId);
    referenceable.set("sd", sd);
    referenceable.set("columns", columns);

    return createInstance(referenceable);
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.QUICK_START, e, String.format("%s table entity creation failed", name));
    }
}
 
Example #20
Source File: QuickStart.java    From atlas with Apache License 2.0 6 votes vote down vote up
Id loadProcess(String name, String description, String user, List<Id> inputTables, List<Id> outputTables,
               String queryText, String queryPlan, String queryId, String queryGraph, String... traitNames)
        throws AtlasBaseException {
    try {
        Referenceable referenceable = new Referenceable(LOAD_PROCESS_TYPE, traitNames);
        // super type attributes
        referenceable.set(AtlasClient.NAME, name);
        referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
        referenceable.set("description", description);
        referenceable.set(INPUTS_ATTRIBUTE, inputTables);
        referenceable.set(OUTPUTS_ATTRIBUTE, outputTables);

        referenceable.set("user", user);
        referenceable.set("startTime", System.currentTimeMillis());
        referenceable.set("endTime", System.currentTimeMillis() + 10000);

        referenceable.set("queryText", queryText);
        referenceable.set("queryPlan", queryPlan);
        referenceable.set("queryId", queryId);
        referenceable.set("queryGraph", queryGraph);

        return createInstance(referenceable);
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.QUICK_START, e, String.format("%s process entity creation failed", name));
    }
}
 
Example #21
Source File: NotificationSender.java    From nifi with Apache License 2.0 5 votes vote down vote up
private boolean isAssigned(Id id) {
    try {
        UUID.fromString(id.getId());
    } catch (IllegalArgumentException e) {
        return false;
    }

    return true;
}
 
Example #22
Source File: FalconHookIT.java    From atlas with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #23
Source File: NotificationSender.java    From nifi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, Referenceable> fromReferenceable(Object _refs, Metrics metrics) {
    if (_refs == null) {
        return Collections.emptyMap();
    }

    final Collection<Referenceable> refs = (Collection<Referenceable>) _refs;
    return refs.stream().map(ref -> {
        // This ref is created within this reporting cycle, and it may not have GUID assigned yet, if it is a brand new reference.
        // If cache has the Reference, then use it because instances in the cache are guaranteed to have GUID assigned.
        // Brand new Referenceables have to have all mandatory attributes.
        final String typeName = ref.getTypeName();
        final Id id = ref.getId();
        final String refQualifiedName = (String) ref.get(ATTR_QUALIFIED_NAME);
        final String typedRefQualifiedName = toTypedQualifiedName(typeName, refQualifiedName);

        final Referenceable refFromCacheIfAvailable = typedQualifiedNameToRef.computeIfAbsent(typedRefQualifiedName, k -> {
            if (isAssigned(id)) {
                // If this referenceable has Guid assigned, then add this one to cache.
                guidToTypedQualifiedName.put(id._getId(), typedRefQualifiedName);
            }
            return ref;
        });

        return new Tuple<>(typedRefQualifiedName, refFromCacheIfAvailable);
    }).filter(tuple -> tuple.getValue() != null)
            .collect(toMap(Tuple::getKey, Tuple::getValue));
}
 
Example #24
Source File: QuickStartIT.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testViewIsAdded() throws AtlasServiceException {

    Referenceable view = atlasClientV1.getEntity(QuickStart.VIEW_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.PRODUCT_DIM_VIEW);

    assertEquals(QuickStart.PRODUCT_DIM_VIEW, view.get(AtlasClient.NAME));

    Id productDimId = getTable(QuickStart.PRODUCT_DIM_TABLE).getId();
    Id inputTableId = ((List<Id>) view.get(QuickStart.INPUT_TABLES_ATTRIBUTE)).get(0);
    assertEquals(productDimId, inputTableId);
}
 
Example #25
Source File: AbstractLineageStrategy.java    From nifi with Apache License 2.0 5 votes vote down vote up
private boolean isUnassigned(Id id) {
    try {
        long l = Long.parseLong(id.getId());
        return l < 0;
    } catch (NumberFormatException ne) {
        return false;
    }
}
 
Example #26
Source File: FalconHookIT.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateProcessWithHDFSFeed() throws Exception {
    Cluster cluster = loadEntity(EntityType.CLUSTER, CLUSTER_RESOURCE, "cluster" + random());
    STORE.publish(EntityType.CLUSTER, cluster);

    TypesUtil.Pair<String, Feed> result = getHDFSFeed(FEED_HDFS_RESOURCE, cluster.getName());
    Feed infeed = result.right;
    String infeedId = result.left;

    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);
    assertEquals(processEntity.get(AtlasClient.NAME), process.getName());
    assertEquals(processEntity.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME),
            FalconBridge.getProcessQualifiedName(process.getName(), cluster.getName()));
    assertEquals(((List<Id>)processEntity.get("inputs")).get(0)._getId(), infeedId);
    assertEquals(((List<Id>)processEntity.get("outputs")).get(0)._getId(), outfeedId);
}
 
Example #27
Source File: AtlasObjectIdConverter.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValidValueV1(Object v1Obj, AtlasType type) {
    boolean ret = (v1Obj == null) || v1Obj instanceof Id || v1Obj instanceof Referenceable;

    if (LOG.isDebugEnabled()) {
        LOG.debug("AtlasObjectIdConverter.isValidValueV1(type={}, value={}): {}", (v1Obj != null ? v1Obj.getClass().getCanonicalName() : null), v1Obj, ret);
    }

    return ret;
}
 
Example #28
Source File: AtlasEntityFormatConverter.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValidValueV1(Object v1Obj, AtlasType type) {
    boolean ret = (v1Obj == null) || v1Obj instanceof Id || v1Obj instanceof Referenceable;

    if (LOG.isDebugEnabled()) {
        LOG.debug("AtlasEntityFormatConverter.isValidValueV1(type={}, value={}): {}", (v1Obj != null ? v1Obj.getClass().getCanonicalName() : null), v1Obj, ret);
    }

    return ret;
}
 
Example #29
Source File: GraphHelper.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasEdge getEdgeForLabel(AtlasVertex vertex, String edgeLabel, AtlasEdgeDirection edgeDirection) {
    Iterator<AtlasEdge> iterator = getAdjacentEdgesByLabel(vertex, edgeDirection, edgeLabel);
    AtlasEdge latestDeletedEdge = null;
    long latestDeletedEdgeTime = Long.MIN_VALUE;

    while (iterator != null && iterator.hasNext()) {
        AtlasEdge edge = iterator.next();
        Id.EntityState edgeState = getState(edge);
        if (edgeState == null || edgeState == Id.EntityState.ACTIVE) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found {}", string(edge));
            }

            return edge;
        } else {
            Long modificationTime = edge.getProperty(MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
            if (modificationTime != null && modificationTime >= latestDeletedEdgeTime) {
                latestDeletedEdgeTime = modificationTime;
                latestDeletedEdge = edge;
            }
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Found {}", latestDeletedEdge == null ? "null" : string(latestDeletedEdge));
    }

    //If the vertex is deleted, return latest deleted edge
    return latestDeletedEdge;
}
 
Example #30
Source File: QuickStart.java    From atlas with Apache License 2.0 5 votes vote down vote up
private Id createInstance(Referenceable referenceable) throws Exception {
    String typeName = referenceable.getTypeName();

    String entityJSON = AtlasType.toV1Json(referenceable);
    System.out.println("Submitting new entity= " + entityJSON);
    List<String> guids = metadataServiceClient.createEntity(entityJSON);
    System.out.println("created instance for type " + typeName + ", guid: " + guids);

    // return the Id for created instance with guid
    if (guids.size() > 0) {
        return new Id(guids.get(guids.size() - 1), referenceable.getId().getVersion(), referenceable.getTypeName());
    }

    return null;
}