public void updateFeedEntity(Feed oldFeed, Feed newFeed) {
    LOG.info("Updating feed entity: {}", newFeed.getName());
    Vertex feedEntityVertex = findVertex(oldFeed.getName(), RelationshipType.FEED_ENTITY);
    if (feedEntityVertex == null) {
      LOG.error("Illegal State: Feed entity vertex must exist for {}", oldFeed.getName());
      throw new IllegalStateException(oldFeed.getName() + " entity vertex must exist.");
    }

    updateDataClassification(oldFeed.getTags(), newFeed.getTags(), feedEntityVertex);
    updateGroups(oldFeed.getGroups(), newFeed.getGroups(), feedEntityVertex);
    updateFeedClusters(
        oldFeed.getClusters().getClusters(), newFeed.getClusters().getClusters(), feedEntityVertex);
  }
  @Test(dependsOnMethods = "testOnChange")
  public void testOnFeedEntityChange() throws Exception {
    Feed oldFeed = inputFeeds.get(0);
    Feed newFeed =
        EntityBuilderTestUtil.buildFeed(
            oldFeed.getName(),
            clusterEntity,
            "classified-as=Secured,source=data-warehouse",
            "reporting");
    addStorage(
        newFeed, Storage.TYPE.FILESYSTEM, "jail://global:00/falcon/impression-feed/20140101");

    try {
      configStore.initiateUpdate(newFeed);

      // add cluster
      org.apache.falcon.entity.v0.feed.Cluster feedCluster =
          new org.apache.falcon.entity.v0.feed.Cluster();
      feedCluster.setName(anotherCluster.getName());
      newFeed.getClusters().getClusters().add(feedCluster);

      configStore.update(EntityType.FEED, newFeed);
    } finally {
      configStore.cleanupUpdateInit();
    }

    verifyUpdatedEdges(newFeed);
    Assert.assertEquals(getVerticesCount(service.getGraph()), 22); // +2 = 2 new tags
    Assert.assertEquals(getEdgesCount(service.getGraph()), 35); // +2 = 1 new cluster, 1 new tag
  }
  public void addFeedEntity(Feed feed) {
    LOG.info("Adding feed entity: {}", feed.getName());
    Vertex feedVertex = addVertex(feed.getName(), RelationshipType.FEED_ENTITY);

    addUserRelation(feedVertex);
    addDataClassification(feed.getTags(), feedVertex);
    addGroups(feed.getGroups(), feedVertex);

    for (org.apache.falcon.entity.v0.feed.Cluster feedCluster : feed.getClusters().getClusters()) {
      if (ClusterType.TARGET != feedCluster.getType()) {
        addRelationToCluster(
            feedVertex, feedCluster.getName(), RelationshipLabel.FEED_CLUSTER_EDGE);
      }
    }

    for (org.apache.falcon.entity.v0.feed.Cluster feedCluster : feed.getClusters().getClusters()) {
      if (FeedHelper.isImportEnabled(feedCluster)) {
        addRelationToDatasource(
            feedVertex,
            FeedHelper.getImportDatasourceName(feedCluster),
            RelationshipLabel.DATASOURCE_IMPORT_EDGE);
      }
    }
  }
  private void addClusterAndFeedForReplication() throws Exception {
    // Add cluster
    clusterEntity = addClusterEntity(CLUSTER_ENTITY_NAME, COLO_NAME, "classification=production");
    // Add backup cluster
    Cluster bcpCluster =
        addClusterEntity(BCP_CLUSTER_ENTITY_NAME, "east-coast", "classification=bcp");

    Cluster[] clusters = {clusterEntity, bcpCluster};

    // Add feed
    Feed rawFeed =
        addFeedEntity(
            REPLICATED_FEED,
            clusters,
            "classified-as=Secure",
            "analytics",
            Storage.TYPE.FILESYSTEM,
            "/falcon/raw-click/${YEAR}/${MONTH}/${DAY}");
    // Add uri template for each cluster
    for (org.apache.falcon.entity.v0.feed.Cluster feedCluster :
        rawFeed.getClusters().getClusters()) {
      if (feedCluster.getName().equals(CLUSTER_ENTITY_NAME)) {
        addStorage(
            feedCluster,
            rawFeed,
            Storage.TYPE.FILESYSTEM,
            "/falcon/raw-click/primary/${YEAR}/${MONTH}/${DAY}");
      } else {
        addStorage(
            feedCluster,
            rawFeed,
            Storage.TYPE.FILESYSTEM,
            "/falcon/raw-click/bcp/${YEAR}/${MONTH}/${DAY}");
      }
    }

    // update config store
    try {
      configStore.initiateUpdate(rawFeed);
      configStore.update(EntityType.FEED, rawFeed);
    } finally {
      configStore.cleanupUpdateInit();
    }
    inputFeeds.add(rawFeed);
  }
 private Feed addFeedEntity(
     String feedName,
     Cluster[] clusters,
     String tags,
     String groups,
     Storage.TYPE storageType,
     String uriTemplate)
     throws Exception {
   Feed feed = EntityBuilderTestUtil.buildFeed(feedName, clusters, tags, groups);
   addStorage(feed, storageType, uriTemplate);
   for (org.apache.falcon.entity.v0.feed.Cluster feedCluster : feed.getClusters().getClusters()) {
     if (feedCluster.getName().equals(BCP_CLUSTER_ENTITY_NAME)) {
       feedCluster.setType(ClusterType.TARGET);
     }
   }
   configStore.publish(EntityType.FEED, feed);
   return feed;
 }