Search in sources :

Example 6 with BootstrapConfig

use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.

the class SqlDBManagerTest method shouldARemoveSlash.

@Test
public void shouldARemoveSlash() throws IOException {
    BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", "root", "pass"), ConfigSource.FILE, "./felix", motechDir, "tcp://localhost:61616");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    Properties propertiesToUpdate = new Properties();
    propertiesToUpdate.put("javax.jdo.option.ConnectionURL", "${sql.url}dbname?useSSL=true");
    SqlDBManager sqlDBManager = new SqlDBManagerImpl(coreConfigurationService);
    Properties propertiesAfterUpdate = sqlDBManager.getSqlProperties(propertiesToUpdate);
    assertEquals("jdbc:mysql://localhost:3306/dbname?useSSL=true", propertiesAfterUpdate.getProperty("javax.jdo.option.ConnectionURL"));
    propertiesToUpdate = new Properties();
    propertiesToUpdate.put("javax.jdo.option.ConnectionURL", "${sql.url}/dbname?useSSL=true");
    propertiesAfterUpdate = sqlDBManager.getSqlProperties(propertiesToUpdate);
    assertEquals("jdbc:mysql://localhost:3306/dbname?useSSL=true", propertiesAfterUpdate.getProperty("javax.jdo.option.ConnectionURL"));
}
Also used : SqlDBManager(org.motechproject.commons.sql.service.SqlDBManager) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 7 with BootstrapConfig

use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.

the class OsgiListener method start.

private static void start() {
    LOGGER.debug("Starting OSGi framework...");
    BootstrapConfig bootstrapConfig = null;
    try {
        bootstrapConfig = bootstrapManager.loadBootstrapConfig();
        bootstrapPresent = bootstrapConfig != null;
    } catch (RuntimeException e) {
        LOGGER.info("Unable to load bootstrap config: " + e.getMessage());
    }
    if (bootstrapPresent) {
        service = getOsgiService();
        service.init(bootstrapConfig);
        service.start();
        try {
            // reinitialize the servlet, in case we only just started the http bundle
            // will happen if the user provided bootstrap configuration through the UI
            ProxyServlet proxyServlet = ProxyServlet.getInstance();
            if (proxyServlet != null) {
                proxyServlet.reInit();
            }
        } catch (ServletException e) {
            LOGGER.error("Error while configuring the Proxy Servlet", e);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig)

Example 8 with BootstrapConfig

use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.

the class ConfigFileMonitor method init.

/**
 * Initializes the configuration file monitor. This method will be automatically called after creation and
 * dependency injection. It is done to make sure that injected dependencies are set and ready to use.
 */
@PostConstruct
public void init() throws IOException {
    BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig();
    if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) {
        // allow custom monitors to be injected
        if (fileMonitor == null) {
            fileMonitor = new DefaultFileMonitor(this);
            // allow raw configs, which are one directory down, under /raw/, to be monitored
            fileMonitor.setRecursive(true);
        }
        fileMonitor.setDelay(DELAY);
        final List<File> files = new ArrayList<>();
        try {
            files.addAll(configLoader.findExistingConfigs());
        } catch (MotechConfigurationException ex) {
            LOGGER.error(ex.getMessage(), ex);
            return;
        }
        configurationService.processExistingConfigs(files);
        startFileMonitor();
    }
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) ArrayList(java.util.ArrayList) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) DefaultFileMonitor(org.apache.commons.vfs2.impl.DefaultFileMonitor) File(java.io.File) PostConstruct(javax.annotation.PostConstruct)

Example 9 with BootstrapConfig

use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.

the class ConfigurationServiceTest method shouldIndicateThatConfigFilesAreNotRequiredWhenPlatformConfigurationFileIsPresent.

@Test
public void shouldIndicateThatConfigFilesAreNotRequiredWhenPlatformConfigurationFileIsPresent() throws IOException {
    BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", null, null), ConfigSource.FILE, null, null, "tcp://localhost:61616");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    ConfigLocation configLocation = mock(ConfigLocation.class);
    when(configLocation.hasPlatformConfigurationFile()).thenReturn(true);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    assertFalse(configurationService.requiresConfigurationFiles());
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 10 with BootstrapConfig

use of org.motechproject.config.core.domain.BootstrapConfig in project motech by motech.

the class ConfigurationServiceTest method shouldIndicateThatConfigFilesAreRequiredWhenPlatformConfigurationFileIsMissing.

@Test
public void shouldIndicateThatConfigFilesAreRequiredWhenPlatformConfigurationFileIsMissing() throws IOException {
    BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", null, null), ConfigSource.FILE, null, null, "tcp://localhost:61616");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    ConfigLocation configLocation = mock(ConfigLocation.class);
    when(configLocation.hasPlatformConfigurationFile()).thenReturn(false);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    assertTrue(configurationService.requiresConfigurationFiles());
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

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