use of org.opennms.upgrade.api.OnmsUpgrade in project opennms by OpenNMS.
the class Upgrade method execute.
/**
* Execute.
* <p>Perform the upgrade operations.</p>
*
* @throws OnmsUpgradeException the OpenNMS upgrade exception
*/
public void execute() throws OnmsUpgradeException {
final Map<String, String> mdc = Logging.getCopyOfContextMap();
Logging.putPrefix("upgrade");
log("\n==============================================================================\n");
log("OpenNMS Upgrader");
log("\n==============================================================================\n\n");
log("OpenNMS is currently %s\n", (isOpennmsRunning() ? "running" : "stopped"));
List<OnmsUpgrade> upgradeObjects = getUpgradeObjects();
for (OnmsUpgrade upg : upgradeObjects) {
log("Processing %s: %s\n", upg.getId(), upg.getDescription());
if (isOpennmsRunning()) {
if (upg.requiresOnmsRunning()) {
executeUpgrade(upg);
} else {
log(" Task %s requires that OpenNMS is stopped but it is running (ignoring)\n", upg.getId());
}
} else {
if (upg.requiresOnmsRunning()) {
log(" Task %s requires OpenNMS is running but it is stopped (ignoring)\n", upg.getId());
} else {
executeUpgrade(upg);
}
}
}
log("\nUpgrade completed successfully!\n");
Logging.setContextMap(mdc);
}
use of org.opennms.upgrade.api.OnmsUpgrade in project opennms by OpenNMS.
the class Upgrade method getUpgradeObjects.
/**
* Gets the upgrade objects.
*
* @return the upgrade objects
* @throws OnmsUpgradeException the OpenNMS upgrade exception
*/
protected List<OnmsUpgrade> getUpgradeObjects() throws OnmsUpgradeException {
List<OnmsUpgrade> upgrades = new ArrayList<OnmsUpgrade>();
try {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
provider.addIncludeFilter(new AssignableTypeFilter(OnmsUpgrade.class));
Set<BeanDefinition> components = provider.findCandidateComponents(getClassScope());
for (BeanDefinition component : components) {
if (component.isAbstract()) {
continue;
}
Class<?> cls = Class.forName(component.getBeanClassName());
if (cls.getAnnotation(Ignore.class) != null) {
continue;
}
OnmsUpgrade upgrade = (OnmsUpgrade) cls.newInstance();
upgrades.add(upgrade);
log("Found upgrade task %s\n", upgrade.getId());
}
Collections.sort(upgrades, new OnmsUpgradeComparator());
} catch (Exception e) {
throw new OnmsUpgradeException(" Can't find the upgrade classes because: " + e.getMessage(), e);
}
return upgrades;
}
Aggregations