Search in sources :

Example 56 with Id

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

the class FalconHookIT method getHDFSFeed.

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);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) List(java.util.List) Id(org.apache.atlas.v1.model.instance.Id) Feed(org.apache.falcon.entity.v0.feed.Feed) Location(org.apache.falcon.entity.v0.feed.Location)

Example 57 with Id

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

the class FalconHookIT method verifyFeedLineage.

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));
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) List(java.util.List) Id(org.apache.atlas.v1.model.instance.Id)

Example 58 with Id

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

the class FalconHookIT method testReplicationFeed.

@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);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Cluster(org.apache.falcon.entity.v0.cluster.Cluster) List(java.util.List) Feed(org.apache.falcon.entity.v0.feed.Feed) Test(org.testng.annotations.Test)

Example 59 with Id

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

the class AtlasClientTest method testCreateEntity.

@Test
public void testCreateEntity() throws Exception {
    setupRetryParams();
    AtlasClient atlasClient = new AtlasClient(service, configuration);
    WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.CREATE_ENTITY, service);
    ClientResponse response = mock(ClientResponse.class);
    when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode());
    String jsonResponse = AtlasType.toV1Json(new EntityResult(Arrays.asList("id"), null, null));
    when(response.getEntity(String.class)).thenReturn(jsonResponse.toString());
    when(response.getLength()).thenReturn(jsonResponse.length());
    String entityJson = AtlasType.toV1Json(new Referenceable("type"));
    when(builder.method(anyString(), Matchers.<Class>any(), anyString())).thenReturn(response);
    List<String> ids = atlasClient.createEntity(entityJson);
    assertEquals(ids.size(), 1);
    assertEquals(ids.get(0), "id");
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) WebResource(com.sun.jersey.api.client.WebResource) Matchers.anyString(org.mockito.Matchers.anyString) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 60 with Id

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

the class EntityNotificationDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    Referenceable entity = EntityNotificationTest.getEntity("id");
    String traitName = "MyTrait";
    List<Struct> traits = Collections.singletonList(new Struct(traitName, Collections.<String, Object>emptyMap()));
    EntityNotificationV1 notification = new EntityNotificationV1(entity, EntityNotificationV1.OperationType.TRAIT_ADD, traits);
    List<String> jsonMsgList = new ArrayList<>();
    AbstractNotification.createNotificationMessages(notification, jsonMsgList);
    EntityNotification deserializedNotification = null;
    for (String jsonMsg : jsonMsgList) {
        deserializedNotification = deserializer.deserialize(jsonMsg);
        if (deserializedNotification != null) {
            break;
        }
    }
    assertTrue(deserializedNotification instanceof EntityNotificationV1);
    EntityNotificationV1 entityNotificationV1 = (EntityNotificationV1) deserializedNotification;
    assertEquals(entityNotificationV1.getOperationType(), notification.getOperationType());
    assertEquals(entityNotificationV1.getEntity().getId(), notification.getEntity().getId());
    assertEquals(entityNotificationV1.getEntity().getTypeName(), notification.getEntity().getTypeName());
    assertEquals(entityNotificationV1.getEntity().getTraits(), notification.getEntity().getTraits());
    assertEquals(entityNotificationV1.getEntity().getTrait(traitName), notification.getEntity().getTrait(traitName));
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityNotification(org.apache.atlas.model.notification.EntityNotification) ArrayList(java.util.ArrayList) Struct(org.apache.atlas.v1.model.instance.Struct) 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