Search in sources :

Example 1 with OnmsUpgrade

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);
}
Also used : OnmsUpgrade(org.opennms.upgrade.api.OnmsUpgrade)

Example 2 with OnmsUpgrade

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;
}
Also used : Ignore(org.opennms.upgrade.api.Ignore) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) ArrayList(java.util.ArrayList) OnmsUpgrade(org.opennms.upgrade.api.OnmsUpgrade) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) OnmsUpgradeComparator(org.opennms.upgrade.api.OnmsUpgradeComparator) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) AssignableTypeFilter(org.springframework.core.type.filter.AssignableTypeFilter)

Aggregations

OnmsUpgrade (org.opennms.upgrade.api.OnmsUpgrade)2 ArrayList (java.util.ArrayList)1 Ignore (org.opennms.upgrade.api.Ignore)1 OnmsUpgradeComparator (org.opennms.upgrade.api.OnmsUpgradeComparator)1 OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)1 AssignableTypeFilter (org.springframework.core.type.filter.AssignableTypeFilter)1