InitialContentMigrator { public void migrate() throws IOException, CommitFailedException { if (isTargetInitialized()) { LOG.info("The target is already initialized, no need to copy the seed mount"); } else if (targetNodeStore instanceof Clusterable) { Clusterable dns = (Clusterable) targetNodeStore; String clusterId = dns.getInstanceId(); LOG.info("The target isn't initialized and the cluster id = {}.", clusterId); if (CLUSTER_ID.equals(clusterId)) { LOG.info("This cluster id {} is configured to initialized the repository.", CLUSTER_ID); doMigrate(); } else { LOG.info("Waiting until the repository is initialized by instance {}.", CLUSTER_ID); waitForInitialization(); } } else { LOG.info("Initializing the default mount."); doMigrate(); } } InitialContentMigrator(NodeStore targetNodeStore, NodeStore seedNodeStore, Mount seedMount); void migrate();  }
@Test public void migrateContentWithCheckpoints() throws IOException, CommitFailedException { MemoryNodeStore seed = new MemoryNodeStore(); NodeBuilder root = seed.getRoot().builder(); root.child("first"); root.child("second"); seed.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY); String checkpoint1 = seed.checkpoint(TimeUnit.MINUTES.toMillis(10)); root = seed.getRoot().builder(); root.child("third"); seed.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY); MemoryNodeStore target = new MemoryNodeStore(); NodeBuilder targetRootBuilder = target.getRoot().builder(); targetRootBuilder.child(CLUSTER_CONFIG_NODE); target.merge(targetRootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); MountInfoProvider mip = Mounts.newBuilder().mount("seed", "/first").build(); InitialContentMigrator icm = new InitialContentMigrator(target, seed, mip.getMountByName("seed")); icm.migrate(); NodeState targetRoot = target.getRoot(); assertFalse("Node /first should not have been migrated", targetRoot.hasChildNode("first")); assertTrue("Node /second should have been migrated", targetRoot.hasChildNode("second")); assertTrue("Node /third should have been migrated", targetRoot.hasChildNode("third")); assertTrue(CLUSTER_CONFIG_NODE + " should be retained", targetRoot.hasChildNode(CLUSTER_CONFIG_NODE)); NodeState checkpointTargetRoot = target.retrieve(checkpoint1); assertFalse("Node /first should not have been migrated", checkpointTargetRoot.hasChildNode("first")); assertTrue("Node /second should have been migrated", checkpointTargetRoot.hasChildNode("second")); assertFalse("Node /third should not be visible from the migrated checkpoint", checkpointTargetRoot.hasChildNode("third")); }