use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.
the class BootstrapController method submitForm.
@RequestMapping(value = "/", method = RequestMethod.POST)
public ModelAndView submitForm(@ModelAttribute(BOOTSTRAP_CONFIG) @Valid BootstrapConfigForm form, BindingResult result, HttpServletRequest request) {
if (OsgiListener.isBootstrapPresent()) {
return new ModelAndView(REDIRECT_HOME);
}
if (result.hasErrors()) {
ModelAndView bootstrapView = new ModelAndView(BOOTSTRAP_CONFIG_VIEW);
bootstrapView.addObject("errors", getErrors(result));
addCommonBootstrapViewObjects(bootstrapView);
return bootstrapView;
}
String queueUrl = form.getQueueUrl();
boolean reachable = messageBrokerPingService.pingBroker(queueUrl);
if (!reachable) {
ModelAndView bootstrapView = new ModelAndView(BOOTSTRAP_CONFIG_VIEW);
bootstrapView.addObject(ERRORS, singletonList(getMessage("server.bootstrap.verify.amq.warning", new Object[] { queueUrl }, request)));
addCommonBootstrapViewObjects(bootstrapView);
return bootstrapView;
}
BootstrapConfig bootstrapConfig;
if (form.getOsgiFrameworkStorage() != null) {
bootstrapConfig = new BootstrapConfig(new SQLDBConfig(form.getSqlUrl(), form.getSqlDriver(), form.getSqlUsername(), form.getSqlPassword()), ConfigSource.valueOf(form.getConfigSource()), form.getOsgiFrameworkStorage(), form.getMotechDir(), form.getQueueUrl());
} else {
bootstrapConfig = new BootstrapConfig(new SQLDBConfig(form.getSqlUrl(), form.getSqlDriver(), form.getSqlUsername(), form.getSqlPassword()), ConfigSource.valueOf(form.getConfigSource()), null, form.getMotechDir(), form.getQueueUrl());
}
try {
OsgiListener.saveBootstrapConfig(bootstrapConfig);
} catch (RuntimeException e) {
LOGGER.error("Error while saving bootstrap configuration", e);
ModelAndView bootstrapView = new ModelAndView(BOOTSTRAP_CONFIG_VIEW);
bootstrapView.addObject("errors", singletonList(getMessage("server.error.bootstrap.save", request)));
addCommonBootstrapViewObjects(bootstrapView);
return bootstrapView;
}
ModelAndView bootstrapView = new ModelAndView(BOOTSTRAP_CONFIG_VIEW);
bootstrapView.getModelMap().put("redirect", true);
return bootstrapView;
}
use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.
the class BootstrapControllerTest method shouldSaveBootstrapConfig.
@Test
public void shouldSaveBootstrapConfig() throws Exception {
when(messageBrokerTestService.pingBroker("tcp://localhost:61616")).thenReturn(true);
mockMvc.perform(MockMvcRequestBuilders.post("/bootstrap/").param("sqlUrl", "jdbc:mysql://www.someurl.com:3306/").param("sqlDriver", "com.mysql.jdbc.Driver").param("sqlUsername", "some_username").param("sqlPassword", "some_password").param("configSource", "UI").param("queueUrl", "tcp://localhost:61616")).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.view().name("bootstrapconfig")).andExpect(MockMvcResultMatchers.model().attribute("redirect", true));
BootstrapConfig expectedConfigToSave = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://www.someurl.com:3306/", "com.mysql.jdbc.Driver", "some_username", "some_password"), ConfigSource.valueOf("UI"), "./felix", motechDir, "tcp://localhost:61616");
PowerMockito.verifyStatic(times(1));
OsgiListener.saveBootstrapConfig(expectedConfigToSave);
}
use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.
the class StartupControllerTest method shouldInformViewThatConfigFilesNotRequiredWhenConfigSourceIsUI.
@Test
public void shouldInformViewThatConfigFilesNotRequiredWhenConfigSourceIsUI() throws IOException {
when(configurationService.requiresConfigurationFiles()).thenReturn(true);
when(localeService.getUserLocale(httpServletRequest)).thenReturn(new Locale("en"));
BootstrapConfig bootstrapConfig = mock(BootstrapConfig.class);
when(bootstrapConfig.getConfigSource()).thenReturn(ConfigSource.UI);
when(configurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
StartupViewData startupViewData = startupController.getStartupViewData(httpServletRequest);
assertThat(startupViewData.getRequireConfigFiles(), Is.is(false));
verify(configurationService, never()).requiresConfigurationFiles();
}
use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.
the class BundleDirectoryManager method init.
@PostConstruct
public void init() {
BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig();
bundleDir = bootstrapConfig.getMotechDir() + "/bundles";
}
use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.
the class StartupManager method startup.
@PostConstruct
public void startup() {
configurationService.evictMotechSettingsCache();
BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig();
if (bootstrapConfig == null) {
LOGGER.info("Bootstrap config required from the user.");
markPlatformStateAs(NEED_BOOTSTRAP_CONFIG);
return;
}
if (configurationService.requiresConfigurationFiles()) {
markPlatformStateAs(NEED_CONFIG);
return;
}
dbSettings = configurationService.getPlatformSettings();
if (bootstrapConfig.getConfigSource() == ConfigSource.FILE) {
motechSettings = configurationService.loadConfig();
syncSettingsWithDb();
}
if (!dbSettings.isPlatformInitialized()) {
if (bootstrapConfig.getConfigSource() == ConfigSource.FILE) {
LOGGER.info("Config source is FILE, and no settings in DB.");
// only require input on the first user if we don't have an admin in db in repository mode
if (needAdmin()) {
LOGGER.info("We require input on the active admin user");
markPlatformStateAs(NEED_CONFIG);
} else {
markPlatformStateAs(NORMAL_RUN);
}
} else {
LOGGER.info("Config source is UI, and no settings in DB. Entering startup.");
markPlatformStateAs(NEED_CONFIG);
}
} else {
if (needAdmin()) {
LOGGER.info("Found settings in db, but there is no active admin user. Entering startup");
markPlatformStateAs(NEED_CONFIG);
return;
}
LOGGER.info("Found settings in db, normal run");
markPlatformStateAs(NORMAL_RUN);
}
if (canLaunchBundles()) {
// send an OSGI event indicating that the modules can be started
eventAdmin.postEvent(new Event(PlatformConstants.STARTUP_TOPIC, new HashMap<>()));
}
}
Aggregations