use of org.opennms.netmgt.config.ServiceConfigFactory in project opennms by OpenNMS.
the class EOLServiceConfigMigratorOfflineTest method testUpgradeConfig.
/**
* Test fixing the configuration file.
*
* @throws Exception the exception
*/
@Test
public void testUpgradeConfig() throws Exception {
File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.SERVICE_CONF_FILE_NAME);
ServiceConfiguration cfg = JaxbUtils.unmarshal(ServiceConfiguration.class, cfgFile);
// check the total and active services before doing the upgrade
assertEquals(m_totalBefore, cfg.getServices().size());
// perform the upgrade
final EOLServiceConfigMigratorOffline migrator = new EOLServiceConfigMigratorOffline();
migrator.execute();
// confirm the total and active services after the upgrade
cfg = JaxbUtils.unmarshal(ServiceConfiguration.class, cfgFile);
final ServiceConfigFactory factory = new ServiceConfigFactory();
Assert.assertEquals(m_totalAfter, cfg.getServices().size());
Assert.assertEquals(m_enabledAfter, factory.getServices().length);
for (final Service svc : cfg.getServices()) {
final String serviceName = svc.getName();
if (m_disabled.contains(serviceName)) {
assertFalse("Service " + serviceName + " should be disabled.", svc.isEnabled());
}
}
for (final Service svc : factory.getServices()) {
final String serviceName = svc.getName();
assertFalse("Service " + serviceName + " should not be in the active service list.", m_disabled.contains(svc.getName()));
}
}
use of org.opennms.netmgt.config.ServiceConfigFactory in project opennms by OpenNMS.
the class ServiceConfig1701MigratorOfflineTest method testUpgradeConfig.
/**
* Test fixing the configuration file.
*
* @throws Exception the exception
*/
@Test
public void testUpgradeConfig() throws Exception {
File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.SERVICE_CONF_FILE_NAME);
ServiceConfiguration cfg = JaxbUtils.unmarshal(ServiceConfiguration.class, cfgFile);
// check the total and active services before doing the upgrade
assertEquals(m_totalBefore, cfg.getServices().size());
// perform the upgrade
final ServiceConfig1701MigratorOffline migrator = new ServiceConfig1701MigratorOffline();
migrator.execute();
// confirm the total and active services after the upgrade
cfg = JaxbUtils.unmarshal(ServiceConfiguration.class, cfgFile);
final ServiceConfigFactory factory = new ServiceConfigFactory();
Assert.assertEquals(m_totalAfter, cfg.getServices().size());
Assert.assertEquals(m_enabledAfter, factory.getServices().length);
for (final Service svc : cfg.getServices()) {
final String serviceName = svc.getName();
if (m_disabled.contains(serviceName)) {
assertFalse("Service " + serviceName + " should be disabled.", svc.isEnabled());
}
}
for (final Service svc : factory.getServices()) {
final String serviceName = svc.getName();
assertFalse("Service " + serviceName + " should not be in the active service list.", m_disabled.contains(svc.getName()));
}
}
use of org.opennms.netmgt.config.ServiceConfigFactory in project opennms by OpenNMS.
the class ServiceConfigMigratorOfflineTest method testFixingConfig.
/**
* Test fixing the configuration file.
*
* @throws Exception the exception
*/
@Test
public void testFixingConfig() throws Exception {
ServiceConfigMigratorOffline migrator = new ServiceConfigMigratorOffline();
migrator.execute();
// Checking parsing the fixed file (it should contain all the services)
File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.SERVICE_CONF_FILE_NAME);
ServiceConfiguration cfg = JaxbUtils.unmarshal(ServiceConfiguration.class, cfgFile);
// Do not change this value: the config file behind this test should always contain
// the content for OpenNMS 14.0.0, regardless of whether or not services are added,
// changed, or removed in the latest version.
Assert.assertEquals(38, cfg.getServices().size());
// Checking Service Factory (it should return only the enabled services)
ServiceConfigFactory factory = new ServiceConfigFactory();
Assert.assertEquals(27, factory.getServices().length);
}
use of org.opennms.netmgt.config.ServiceConfigFactory in project opennms by OpenNMS.
the class Starter method start.
private void start() {
LOG.debug("Beginning startup");
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Invoker invoker = new Invoker();
invoker.setServer(server);
invoker.setAtType(InvokeAtType.START);
List<InvokerService> services = InvokerService.createServiceList(new ServiceConfigFactory().getServices());
invoker.setServices(services);
invoker.instantiateClasses();
List<InvokerResult> resultInfo = invoker.invokeMethods();
for (InvokerResult result : resultInfo) {
if (result != null && result.getThrowable() != null) {
Service service = result.getService();
String name = service.getName();
String className = service.getClassName();
String message = "An error occurred while attempting to start the \"" + name + "\" service (class " + className + "). " + "Shutting down and exiting.";
LOG.error(message, result.getThrowable());
System.err.println(message);
result.getThrowable().printStackTrace();
Manager manager = new Manager();
manager.stop();
manager.doSystemExit();
// Shouldn't get here
return;
}
}
LOG.debug("Startup complete");
}
Aggregations