}
class ImportExportHandler {
void importFromFileSystem(final Path importPath) {
LockHandle writeLock = aquireWriteLock();
try {
assertValid();
File sourceDir = importPath.toFile();
IllegalArgumentAssertion.assertTrue(sourceDir.isDirectory(), "Not a valid source dir: " + sourceDir);
// lets try and detect the old ZooKeeper style file layout and transform it into the git layout
// so we may /fabric/configs/versions/1.0/profiles => /fabric/profiles in branch 1.0
File fabricDir = new File(sourceDir, "fabric");
File configs = new File(fabricDir, "configs");
String defaultVersion = dataStore.get().getDefaultVersion();
if (configs.exists()) {
LOGGER.info("Importing the old ZooKeeper layout");
File versions = new File(configs, "versions");
if (versions.exists() && versions.isDirectory()) {
File[] files = versions.listFiles();
if (files != null) {
for (File versionFolder : files) {
String version = versionFolder.getName();
if (versionFolder.isDirectory()) {
File[] versionFiles = versionFolder.listFiles();
if (versionFiles != null) {
for (File versionFile : versionFiles) {
LOGGER.info("Importing version configuration " + versionFile + " to branch " + version);
importFromFileSystem(versionFile, GitHelpers.CONFIGS, version, true);
}
}
}
}
}
}
File metrics = new File(fabricDir, "metrics");
if (metrics.exists()) {
LOGGER.info("Importing metrics from " + metrics + " to branch " + defaultVersion);
importFromFileSystem(metrics, GitHelpers.CONFIGS, defaultVersion, false);
}
} else {
// default to version 1.0
String version = "1.0";
LOGGER.info("Importing " + fabricDir + " as version " + version);
importFromFileSystem(fabricDir, "", version, false);
}
} finally {
writeLock.unlock();
}
}