Search in sources :

Example 1 with ProcessProperties

use of org.sonar.process.ProcessProperties in project sonarqube by SonarSource.

the class CommandFactoryImplTest method newFactory.

private CommandFactoryImpl newFactory(Properties userProps, System2 system2) {
    Properties p = new Properties();
    p.setProperty("sonar.path.home", homeDir.getAbsolutePath());
    p.setProperty("sonar.path.temp", tempDir.getAbsolutePath());
    p.setProperty("sonar.path.logs", logsDir.getAbsolutePath());
    p.putAll(userProps);
    Props props = new Props(p);
    ServiceLoaderWrapper serviceLoaderWrapper = mock(ServiceLoaderWrapper.class);
    when(serviceLoaderWrapper.load()).thenReturn(ImmutableSet.of());
    new ProcessProperties(serviceLoaderWrapper).completeDefaults(props);
    return new CommandFactoryImpl(props, tempDir, system2);
}
Also used : ServiceLoaderWrapper(org.sonar.core.extension.ServiceLoaderWrapper) Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) Props(org.sonar.process.Props) ProcessProperties(org.sonar.process.ProcessProperties)

Example 2 with ProcessProperties

use of org.sonar.process.ProcessProperties in project sonarqube by SonarSource.

the class AppSettingsLoaderImpl method load.

@Override
public AppSettings load() {
    Properties p = loadPropertiesFile(homeDir);
    Set<String> keysOverridableFromEnv = stream(ProcessProperties.Property.values()).map(ProcessProperties.Property::getKey).collect(Collectors.toSet());
    keysOverridableFromEnv.addAll(p.stringPropertyNames());
    // 1st pass to load static properties
    Props staticProps = reloadProperties(keysOverridableFromEnv, p);
    keysOverridableFromEnv.addAll(getDynamicPropertiesKeys(staticProps));
    // 2nd pass to load dynamic properties like `ldap.*.url` or `ldap.*.baseDn` which keys depend on values of static
    // properties loaded in 1st step
    Props props = reloadProperties(keysOverridableFromEnv, p);
    new ProcessProperties(serviceLoaderWrapper).completeDefaults(props);
    stream(consumers).forEach(c -> c.accept(props));
    return new AppSettingsImpl(props);
}
Also used : Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) Props(org.sonar.process.Props) ProcessProperties(org.sonar.process.ProcessProperties)

Example 3 with ProcessProperties

use of org.sonar.process.ProcessProperties in project sonarqube by SonarSource.

the class SearchServerTest method start_stop_server.

@Test
public void start_stop_server() throws Exception {
    Props props = new Props(new Properties());
    // the following properties have always default values (see ProcessProperties)
    InetAddress host = InetAddress.getLoopbackAddress();
    props.set(ProcessProperties.SEARCH_HOST, host.getHostAddress());
    props.set(ProcessProperties.SEARCH_PORT, String.valueOf(port));
    props.set(ProcessProperties.CLUSTER_NAME, A_CLUSTER_NAME);
    props.set(EsSettings.CLUSTER_SEARCH_NODE_NAME, A_NODE_NAME);
    props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath());
    props.set(ProcessEntryPoint.PROPERTY_SHARED_PATH, temp.newFolder().getAbsolutePath());
    underTest = new SearchServer(props);
    underTest.start();
    assertThat(underTest.getStatus()).isEqualTo(Monitored.Status.OPERATIONAL);
    Settings settings = Settings.builder().put("cluster.name", A_CLUSTER_NAME).build();
    client = TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(host, port));
    assertThat(client.admin().cluster().prepareClusterStats().get().getStatus()).isEqualTo(ClusterHealthStatus.GREEN);
    underTest.stop();
    underTest.awaitStop();
    underTest = null;
    try {
        client.admin().cluster().prepareClusterStats().get();
        fail();
    } catch (NoNodeAvailableException exception) {
    // ok
    }
}
Also used : Props(org.sonar.process.Props) Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) InetAddress(java.net.InetAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 4 with ProcessProperties

use of org.sonar.process.ProcessProperties in project sonarqube by SonarSource.

the class EsSettingsTest method minProps.

private Props minProps(boolean cluster, @Nullable String host, @Nullable String port) throws IOException {
    File homeDir = temp.newFolder();
    Props props = new Props(new Properties());
    ServiceLoaderWrapper serviceLoaderWrapper = mock(ServiceLoaderWrapper.class);
    when(serviceLoaderWrapper.load()).thenReturn(ImmutableSet.of());
    new ProcessProperties(serviceLoaderWrapper).completeDefaults(props);
    props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath());
    props.set(Property.CLUSTER_ENABLED.getKey(), Boolean.toString(cluster));
    if (cluster) {
        ofNullable(host).ifPresent(h -> props.set(CLUSTER_NODE_ES_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(CLUSTER_NODE_ES_PORT.getKey(), p));
        ofNullable(host).ifPresent(h -> props.set(CLUSTER_NODE_SEARCH_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(CLUSTER_NODE_SEARCH_PORT.getKey(), p));
        ofNullable(port).ifPresent(h -> props.set(CLUSTER_ES_HOSTS.getKey(), h));
    } else {
        ofNullable(host).ifPresent(h -> props.set(SEARCH_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(SEARCH_PORT.getKey(), p));
    }
    return props;
}
Also used : ServiceLoaderWrapper(org.sonar.core.extension.ServiceLoaderWrapper) Props(org.sonar.process.Props) Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) File(java.io.File) ProcessProperties(org.sonar.process.ProcessProperties)

Aggregations

Properties (java.util.Properties)4 ProcessProperties (org.sonar.process.ProcessProperties)4 Props (org.sonar.process.Props)4 ServiceLoaderWrapper (org.sonar.core.extension.ServiceLoaderWrapper)2 File (java.io.File)1 InetAddress (java.net.InetAddress)1 NoNodeAvailableException (org.elasticsearch.client.transport.NoNodeAvailableException)1 Settings (org.elasticsearch.common.settings.Settings)1 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)1 Test (org.junit.Test)1