use of org.commonjava.indy.action.IndyLifecycleException in project indy by Commonjava.
the class LegacyQuartzDBMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
final Logger logger = LoggerFactory.getLogger(LegacyQuartzDBMigrationAction.class);
Path path = Paths.get(fileConfig.getDataBasedir().toURI());
final Stream<Path> listFiles;
try {
listFiles = Files.list(path);
} catch (IOException e) {
logger.warn("IOException happened when list path {}", path);
return false;
}
if (listFiles != null) {
listFiles.filter(filePath -> Files.isRegularFile(filePath) && filePath.getFileName().toString().startsWith(SCHEDULE_DB_NAME)).forEach(file -> {
try {
Files.delete(file);
} catch (IOException e) {
logger.warn("IOException happened when delete file {}", file);
}
});
}
return true;
}
use of org.commonjava.indy.action.IndyLifecycleException in project indy by Commonjava.
the class LegacyDataMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
if (!(storeDataManager instanceof DataFileStoreDataManager)) {
logger.info("Store manager: {} is not based on DataFile's. Skipping migration.", storeDataManager.getClass().getName());
return false;
}
final DataFile basedir = dataFileManager.getDataFile(INDY_STORE);
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Migrating legacy store definitions.");
if (!basedir.exists()) {
return false;
}
StoreType[] storeTypes = StoreType.values();
final String[] dirs = basedir.list();
if (dirs == null || dirs.length < 1) {
return false;
}
Map<String, String> migrationCandidates = new HashMap<>();
//noinspection ConstantConditions
Stream.of(storeTypes).forEach(type -> {
File[] files = basedir.getDetachedFile().toPath().resolve(type.singularEndpointName()).toFile().listFiles((dir, fname) -> fname.endsWith(".json"));
if (files != null) {
Stream.of(files).forEach((f) -> {
String src = Paths.get(type.singularEndpointName(), f.getName()).toString();
String target = Paths.get(MAVEN_PKG_KEY, type.singularEndpointName(), f.getName()).toString();
migrationCandidates.put(src, target);
});
}
});
boolean changed = false;
for (Map.Entry<String, String> entry : migrationCandidates.entrySet()) {
DataFile src = dataFileManager.getDataFile(INDY_STORE, entry.getKey());
DataFile target = dataFileManager.getDataFile(INDY_STORE, entry.getValue());
if (target.exists()) {
continue;
}
DataFile targetDir = target.getParent();
if (!targetDir.exists() && !targetDir.mkdirs()) {
throw new IndyLifecycleException("Cannot make directory: %s.", targetDir.getPath());
} else if (!targetDir.isDirectory()) {
throw new IndyLifecycleException("Not a directory: %s.", targetDir.getPath());
}
try {
logger.info("Migrating definition {}", src.getPath());
final String json = src.readString();
final String migrated = objectMapper.patchLegacyStoreJson(json);
target.writeString(migrated, summary);
changed = true;
} catch (final IOException e) {
throw new IndyLifecycleException("Failed to migrate artifact-store definition from: %s to: %s. Reason: %s", e, src, target, e.getMessage(), e);
}
}
if (changed) {
try {
storeDataManager.reload();
} catch (IndyDataException e) {
throw new IndyLifecycleException("Failed to reload migrated store definitions: %s", e, e.getMessage());
}
}
return changed;
}
use of org.commonjava.indy.action.IndyLifecycleException in project indy by Commonjava.
the class PackageTypedStorageMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
Set<ArtifactStore> stores;
try {
stores = storeDataManager.getAllArtifactStores();
} catch (IndyDataException e) {
throw new IndyLifecycleException("Cannot retrieve list of repositories and groups in order to review storage locations. Reason: %s", e, e.getMessage());
}
File storageRoot = config.getStorageRootDirectory();
File nfsStorageRoot = config.getNFSStorageRootDirectory();
int migrations = 0;
Map<File, File> unmigratedNfs = new HashMap<>();
for (ArtifactStore store : stores) {
File old = deprecatedStoragePath(storageRoot, store);
File migrated = packageTypedStoragePath(storageRoot, store);
if (old.exists()) {
logger.info("Attempting to migrate existing storage from old directory structure: {} " + "to package-typed structure: {}", old, migrated);
try {
if (migrated.exists()) {
FileUtils.copyDirectory(old, migrated);
FileUtils.forceDelete(old);
} else {
FileUtils.moveDirectory(old, migrated);
}
migrations++;
} catch (IOException e) {
throw new IndyLifecycleException("Failed to migrate: %s to: %s. Reason: %s", e, old, migrated);
}
}
if (nfsStorageRoot != null) {
File oldNfs = deprecatedStoragePath(nfsStorageRoot, store);
File migratedNfs = packageTypedStoragePath(nfsStorageRoot, store);
if (oldNfs.exists() && !migratedNfs.exists()) {
unmigratedNfs.put(oldNfs, migratedNfs);
}
}
}
if (!unmigratedNfs.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("ERROR: Un-migrated directories detected on NFS storage!!!!");
sb.append("\n\nThese directories still use the old <type>/<name> directory format. Indy now supports");
sb.append("\nmultiple package types, and the storage format has changed accordingly. The new format is:");
sb.append("\n\n <package-type>/<type>/<name>");
sb.append("\n\nPlease migrate these NFS directories manually. For Maven repositories:");
sb.append("\n\n maven/<type>/<name>");
sb.append("\n\nFor HTTProx repositories (httprox_*):");
sb.append("\n\n generic-http/<type>/<name>");
sb.append("\n\nThe following directories were detected:\n");
unmigratedNfs.forEach((o, n) -> sb.append("\n ").append(o).append(" => ").append(n));
sb.append("\n\n");
logger.error(sb.toString());
throw new IndyLifecycleException("Un-migrated NFS directories detected. Indy cannot start until this has been resolved.");
}
return migrations > 0;
}
Aggregations