Search in sources :

Example 11 with BootstrapConfig

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;
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with BootstrapConfig

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);
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with BootstrapConfig

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();
}
Also used : Locale(java.util.Locale) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) StartupViewData(org.motechproject.server.web.dto.StartupViewData) Test(org.junit.Test)

Example 14 with BootstrapConfig

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";
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) PostConstruct(javax.annotation.PostConstruct)

Example 15 with BootstrapConfig

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<>()));
    }
}
Also used : HashMap(java.util.HashMap) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Event(org.osgi.service.event.Event) PostConstruct(javax.annotation.PostConstruct)

Aggregations

BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)30 Test (org.junit.Test)23 SQLDBConfig (org.motechproject.config.core.domain.SQLDBConfig)17 Properties (java.util.Properties)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 File (java.io.File)4 Locale (java.util.Locale)3 PostConstruct (javax.annotation.PostConstruct)3 ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)3 StartupViewData (org.motechproject.server.web.dto.StartupViewData)3 ArrayList (java.util.ArrayList)2 SqlDBManager (org.motechproject.commons.sql.service.SqlDBManager)2 MotechConfigurationException (org.motechproject.config.core.exception.MotechConfigurationException)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DefaultFileMonitor (org.apache.commons.vfs2.impl.DefaultFileMonitor)1