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);
}
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));
}
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);
}
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");
}
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));
}
Aggregations