private static int getProcessNumber(Props props) { return Integer.parseInt(props.nonNullValue(PROPERTY_PROCESS_INDEX)); }
private static File ensurePropertyIsAbsolutePath(Props props, String propKey) { // default values are set by ProcessProperties String path = props.nonNullValue(propKey); File d = new File(path); if (!d.isAbsolute()) { File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); d = new File(homeDir, path); LOG.trace("Overriding property {} from relative path '{}' to absolute path '{}'", propKey, path, d.getAbsolutePath()); props.set(propKey, d.getAbsolutePath()); } return d; }
private static void verifyUnchanged(Props initialProps, Props newProps, String propKey) { String initialValue = initialProps.nonNullValue(propKey); String newValue = newProps.nonNullValue(propKey); if (!Objects.equals(initialValue, newValue)) { throw new MessageException(format("Property [%s] cannot be changed on restart: [%s] => [%s]", propKey, initialValue, newValue)); } }
private ProcessEntryPoint(Props props, int processNumber, File sharedDir, SystemExit exit, ProcessCommands commands) { this.props = props; this.processKey = props.nonNullValue(PROPERTY_PROCESS_KEY); this.processNumber = processNumber; this.sharedDir = sharedDir; this.exit = exit; this.commands = commands; this.stopWatcher = new StopWatcher(commands, this); }
private static List<File> buildOutdatedSearchDirs(Props props) { String dataPath = props.nonNullValue(PATH_DATA.getKey()); return Collections.singletonList(new File(dataPath, "es")); }
private static File buildDataDir(Props props) { String dataPath = props.nonNullValue(PATH_DATA.getKey()); return new File(dataPath, "es5"); }
private static EsConnector createEsConnector(Props props) { String searchHosts = props.nonNullValue(CLUSTER_SEARCH_HOSTS.getKey()); Set<HostAndPort> hostAndPorts = Arrays.stream(searchHosts.split(",")) .map(HostAndPort::fromString) .collect(Collectors.toSet()); return new EsConnectorImpl(props.nonNullValue(CLUSTER_NAME.getKey()), hostAndPorts); } }
public T addFromMandatoryProperty(Props props, String propertyName) { String value = props.nonNullValue(propertyName); if (!value.isEmpty()) { List<String> jvmOptions = Arrays.stream(value.split(" (?=-)")).map(String::trim).collect(Collectors.toList()); checkOptionFormat(propertyName, jvmOptions); checkMandatoryOptionOverwrite(propertyName, jvmOptions); options.addAll(jvmOptions); } return castThis(); }
private InetAddress readHost() { String hostProperty = props.nonNullValue(SEARCH_HOST.getKey()); try { return InetAddress.getByName(hostProperty); } catch (UnknownHostException e) { throw new IllegalStateException("Can not resolve host [" + hostProperty + "]. Please check network settings and property " + SEARCH_HOST.getKey(), e); } }
private static void fixPortIfZero(Props props, String addressPropertyKey, String portPropertyKey) { String port = props.value(portPropertyKey); if ("0".equals(port)) { String address = props.nonNullValue(addressPropertyKey); try { props.set(portPropertyKey, String.valueOf(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getByName(address)))); } catch (UnknownHostException e) { throw new IllegalStateException("Cannot resolve address [" + address + "] set by property [" + addressPropertyKey + "]", e); } } } }
private void ensureLocalButNotLoopbackAddress(Props props, String propertyKey) { String propertyValue = props.nonNullValue(propertyKey).trim(); try { InetAddress address = network.toInetAddress(propertyValue); if (!network.isLocalInetAddress(address) || network.isLoopbackInetAddress(address)) { throw new MessageException(format("Property %s must be a local non-loopback address: %s", propertyKey, propertyValue)); } } catch (UnknownHostException | SocketException e) { throw new MessageException(format("Property %s must be a local non-loopback address: %s [%s]", propertyKey, propertyValue, e.getMessage())); } }
private static HazelcastMember createHzMember(Props props) { HazelcastMemberBuilder builder = new HazelcastMemberBuilder() .setNetworkInterface(props.nonNullValue(CLUSTER_NODE_HOST.getKey())) .setMembers(asList(props.nonNullValue(CLUSTER_HZ_HOSTS.getKey()).split(","))) .setNodeName(props.nonNullValue(CLUSTER_NODE_NAME.getKey())) .setPort(Integer.parseInt(props.nonNullValue(CLUSTER_NODE_HZ_PORT.getKey()))) .setProcessId(ProcessId.APP); return builder.build(); }
public EsSettings(Props props, EsInstallation fileSystem, System2 system2) { this.props = props; this.fileSystem = fileSystem; this.clusterName = props.nonNullValue(CLUSTER_NAME.getKey()); this.clusterEnabled = props.valueAsBoolean(CLUSTER_ENABLED.getKey()); if (this.clusterEnabled) { this.nodeName = props.value(CLUSTER_NODE_NAME.getKey(), "sonarqube-" + UUID.randomUUID().toString()); } else { this.nodeName = STANDALONE_NODE_NAME; } String esJvmOptions = system2.getenv("ES_JVM_OPTIONS"); if (esJvmOptions != null && !esJvmOptions.trim().isEmpty()) { LOGGER.warn("ES_JVM_OPTIONS is defined but will be ignored. " + "Use sonar.search.javaOpts and/or sonar.search.javaAdditionalOpts in sonar.properties to specify jvm options for Elasticsearch"); } }
@Override public void stopAsync() { if (lifecycle.tryToMoveTo(Lifecycle.State.STOPPING)) { stopperThread = new StopperThread(monitored, commands, Long.parseLong(props.nonNullValue(PROPERTY_TERMINATION_TIMEOUT_MS))); stopperThread.start(); stopWatcher.stopWatching(); } }
@Test public void resolve_H2_provider_when_props_is_empty_and_set_URL_to_default_H2() { Props props = newProps(); assertThat(underTest.resolveProviderAndEnforceNonnullJdbcUrl(props)) .isEqualTo(Provider.H2); assertThat(props.nonNullValue(JDBC_URL.getKey())).isEqualTo(String.format("jdbc:h2:tcp://%s:9092/sonar", InetAddress.getLoopbackAddress().getHostAddress())); }
@Test @UseDataProvider("beforeAndAfterBlanks") public void nonNullValue(String blankBefore, String blankAfter) { Properties p = new Properties(); p.setProperty("foo", blankBefore + "bar" + blankAfter); Props props = new Props(p); assertThat(props.nonNullValue("foo")).isEqualTo("bar"); }
SearchNodeHealthProvider(Props props, ClusterAppState clusterAppState, NetworkUtils networkUtils, Clock clock) { this.clusterAppState = clusterAppState; this.nodeDetails = NodeDetails.newNodeDetailsBuilder() .setType(NodeDetails.Type.SEARCH) .setName(props.nonNullValue(CLUSTER_NODE_NAME.getKey())) .setHost(getHost(props, networkUtils)) .setPort(Integer.valueOf(props.nonNullValue(CLUSTER_NODE_HZ_PORT.getKey()))) .setStartedAt(clock.now()) .build(); }
private void checkProviderForUrlAndUnchangedUrl(String url, Provider expected) { Props props = newProps(JDBC_URL.getKey(), url); assertThat(underTest.resolveProviderAndEnforceNonnullJdbcUrl(props)).isEqualTo(expected); assertThat(props.nonNullValue(JDBC_URL.getKey())).isEqualTo(url); }
@Test @UseDataProvider("beforeAndAfterBlanks") public void nonNullValue_return_empty_string_IAE_on_existing_key_with_blank_value(String blankBefore, String blankAfter) { Properties p = new Properties(); p.setProperty("blank", blankBefore + blankAfter); Props props = new Props(p); assertThat(props.nonNullValue("blank")).isEmpty(); }
@Test public void nonNullValue_throws_IAE_on_non_existing_key() { Props props = new Props(new Properties()); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Missing property: other"); props.nonNullValue("other"); }