import org.sonar.db.DbClient;
import org.sonar.db.DefaultDatabase;
import org.sonar.db.purge.PurgeProfiler;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
import org.sonar.process.logging.LogbackHelper;
import org.sonar.server.platform.db.migration.MigrationConfigurationModule;
import org.sonar.server.platform.db.migration.version.DatabaseVersion;
import org.sonar.server.platform.monitoring.DatabaseSection;
-import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
import org.sonar.server.platform.monitoring.cluster.LoggingSection;
+import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
import org.sonar.server.plugins.InstalledPluginReferentialFactory;
import org.sonar.server.plugins.ServerExtensionInstaller;
import org.sonar.server.plugins.privileged.PrivilegedPluginsBootstraper;
SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.COMPUTE_ENGINE),
CeProcessLogging.class,
UuidFactoryImpl.INSTANCE,
- NetworkUtils.INSTANCE,
+ NetworkUtilsImpl.INSTANCE,
WebServerImpl.class,
LogbackHelper.class,
DefaultDatabase.class,
import org.sonar.ce.StandaloneCeDistributedInformation;
import org.sonar.db.DbTester;
import org.sonar.db.property.PropertyDto;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessId;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
@Test
public void real_start_with_cluster() throws IOException {
- Optional<InetAddress> localhost = NetworkUtils.INSTANCE.getLocalNonLoopbackIpv4Address();
+ Optional<InetAddress> localhost = NetworkUtilsImpl.INSTANCE.getLocalNonLoopbackIpv4Address();
// test is ignored if offline
assumeThat(localhost.isPresent(), CoreMatchers.is(true));
properties.setProperty(CLUSTER_ENABLED, "true");
properties.setProperty(CLUSTER_NODE_TYPE, "application");
properties.setProperty(CLUSTER_NODE_HOST, localhost.get().getHostAddress());
- properties.setProperty(CLUSTER_NODE_PORT, "" + NetworkUtils.INSTANCE.getNextAvailablePort(localhost.get()));
+ properties.setProperty(CLUSTER_NODE_PORT, "" + NetworkUtilsImpl.INSTANCE.getNextAvailablePort(localhost.get()));
// required persisted properties
insertProperty(CoreProperties.SERVER_ID, "a_startup_id");
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessId;
public class AppStateImpl implements AppState {
@Override
public Optional<String> getLeaderHostName() {
- return Optional.of(NetworkUtils.INSTANCE.getHostname());
+ return Optional.of(NetworkUtilsImpl.INSTANCE.getHostname());
}
@Override
import org.sonar.application.config.AppSettings;
import org.sonar.application.config.ClusterSettings;
import org.sonar.process.MessageException;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessId;
import org.sonar.process.cluster.NodeType;
import org.sonar.process.cluster.hz.HazelcastMember;
import static java.lang.String.format;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.HOSTNAME;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.IP_ADDRESSES;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_TYPE;
import static org.sonar.process.cluster.hz.HazelcastObjects.CLUSTER_NAME;
import static org.sonar.process.cluster.hz.HazelcastObjects.LEADER;
import static org.sonar.process.cluster.hz.HazelcastObjects.OPERATIONAL_PROCESSES;
nodeDisconnectedListenerUUID = hzMember.getCluster().addMembershipListener(new NodeDisconnectedListener());
if (ClusterSettings.isLocalElasticsearchEnabled(settings)) {
- this.healthStateSharing = new HealthStateSharingImpl(hzMember, new SearchNodeHealthProvider(settings.getProps(), this, NetworkUtils.INSTANCE));
+ this.healthStateSharing = new HealthStateSharingImpl(hzMember, new SearchNodeHealthProvider(settings.getProps(), this, NetworkUtilsImpl.INSTANCE));
this.healthStateSharing.start();
}
}
Optional<Member> leader = hzMember.getCluster().getMembers().stream().filter(m -> m.getUuid().equals(leaderId)).findFirst();
if (leader.isPresent()) {
return Optional.of(
- format("%s (%s)", leader.get().getStringAttribute(HazelcastMember.Attribute.HOSTNAME), leader.get().getStringAttribute(HazelcastMember.Attribute.IP_ADDRESSES)));
+ format("%s (%s)", leader.get().getStringAttribute(HOSTNAME.getKey()), leader.get().getStringAttribute(IP_ADDRESSES.getKey())));
}
}
return Optional.empty();
}
private boolean isAppNode(Member member) {
- return NodeType.APPLICATION.getValue().equals(member.getStringAttribute(HazelcastMember.Attribute.NODE_TYPE));
+ return NodeType.APPLICATION.getValue().equals(member.getStringAttribute(NODE_TYPE.getKey()));
}
private void removeOperationalProcess(String uuid) {
import java.util.function.Consumer;
import org.slf4j.LoggerFactory;
import org.sonar.process.ConfigurationUtils;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
public AppSettingsLoaderImpl(String[] cliArguments) {
this(cliArguments, detectHomeDir(),
- new FileSystemSettings(), new JdbcSettings(), new ClusterSettings(NetworkUtils.INSTANCE));
+ new FileSystemSettings(), new JdbcSettings(), new ClusterSettings(NetworkUtilsImpl.INSTANCE));
}
AppSettingsLoaderImpl(String[] cliArguments, File homeDir, Consumer<Props>... consumers) {
import org.junit.Test;
import org.sonar.application.cluster.ClusterAppStateImpl;
import org.sonar.application.config.TestAppSettings;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeThat;
@Test
public void create_cluster_implementation_if_cluster_is_enabled() {
- Optional<InetAddress> ip = NetworkUtils.INSTANCE.getLocalNonLoopbackIpv4Address();
+ Optional<InetAddress> ip = NetworkUtilsImpl.INSTANCE.getLocalNonLoopbackIpv4Address();
assumeThat(ip.isPresent(), CoreMatchers.is(true));
settings.set(CLUSTER_ENABLED, "true");
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessId;
public class TestAppState implements AppState {
@Override
public Optional<String> getLeaderHostName() {
- return Optional.of(NetworkUtils.INSTANCE.getHostname());
+ return Optional.of(NetworkUtilsImpl.INSTANCE.getHostname());
}
@Override
import org.sonar.application.AppStateListener;
import org.sonar.application.config.TestAppSettings;
import org.sonar.process.MessageException;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessId;
import org.sonar.process.cluster.NodeType;
import org.sonar.process.cluster.hz.HazelcastMember;
.setProcessId(ProcessId.COMPUTE_ENGINE)
.setClusterName("foo")
.setNodeName("bar")
- .setPort(NetworkUtils.INSTANCE.getNextAvailablePort(loopback))
+ .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
.setNetworkInterface(loopback.getHostAddress())
.build();
}
import org.junit.rules.ExpectedException;
import org.sonar.process.MessageException;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessProperties;
import static org.junit.Assume.assumeThat;
private InetAddress loopback = InetAddress.getLoopbackAddress();
private InetAddress nonLoopbackLocal;
- private NetworkUtils network = spy(NetworkUtils.INSTANCE);
+ private NetworkUtils network = spy(NetworkUtilsImpl.INSTANCE);
@Before
public void setUp() throws Exception {
import org.junit.rules.ExpectedException;
import org.sonar.process.MessageException;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
public ExpectedException expectedException = ExpectedException.none();
private InetAddress nonLoopbackLocal = InetAddress.getLoopbackAddress();
- private NetworkUtils network = spy(NetworkUtils.INSTANCE);
+ private NetworkUtils network = spy(NetworkUtilsImpl.INSTANCE);
@Before
public void setUp() throws Exception {
import java.util.function.Predicate;
public interface NetworkUtils {
- NetworkUtils INSTANCE = new NetworkUtilsImpl();
int getNextAvailablePort(InetAddress address);
public class NetworkUtilsImpl implements NetworkUtils {
+ public static final NetworkUtils INSTANCE = new NetworkUtilsImpl();
private static final Set<Integer> PORTS_ALREADY_ALLOCATED = new HashSet<>();
private static final int PORT_MAX_TRIES = 50;
if ("0".equals(port)) {
String address = props.nonNullValue(addressPropertyKey);
try {
- props.set(portPropertyKey, String.valueOf(NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getByName(address))));
+ 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);
}
import java.util.Set;
import java.util.stream.Collectors;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME;
+
/**
* Answer of {@link DistributedCall}, aggregating the answers from
* all the target members.
public void propagateExceptions() {
if (!failedMembers.isEmpty()) {
String failedMemberNames = failedMembers.keySet().stream()
- .map(m -> m.getStringAttribute(HazelcastMember.Attribute.NODE_NAME))
+ .map(m -> m.getStringAttribute(NODE_NAME.getKey()))
.collect(Collectors.joining(", "));
throw new IllegalStateException("Distributed cluster action in cluster nodes " + failedMemberNames + " (other nodes may have timed out)",
failedMembers.values().iterator().next());
if (!timedOutMembers.isEmpty()) {
String timedOutMemberNames = timedOutMembers.stream()
- .map(m -> m.getStringAttribute(HazelcastMember.Attribute.NODE_NAME))
+ .map(m -> m.getStringAttribute(NODE_NAME.getKey()))
.collect(Collectors.joining(", "));
throw new IllegalStateException("Distributed cluster action timed out in cluster nodes " + timedOutMemberNames);
}
public interface HazelcastMember extends AutoCloseable {
- interface Attribute {
+ enum Attribute {
/**
* The key of the hostname attribute of a member
*/
- String HOSTNAME = "HOSTNAME";
+ HOSTNAME("HOSTNAME"),
/**
* The key of the ips list attribute of a member
*/
- String IP_ADDRESSES = "IP_ADDRESSES";
+ IP_ADDRESSES("IP_ADDRESSES"),
/**
* The key of the node name attribute of a member
*/
- String NODE_NAME = "NODE_NAME";
+ NODE_NAME("NODE_NAME"),
/**
* The role of the sonar-application inside the SonarQube cluster
* {@link NodeType}
*/
- String NODE_TYPE = "NODE_TYPE";
+ NODE_TYPE("NODE_TYPE"),
/**
* Key of process as defined by {@link ProcessId#getKey()}
*/
- String PROCESS_KEY = "PROCESS_KEY";
+ PROCESS_KEY("PROCESS_KEY");
+
+ private final String key;
+
+ Attribute(String key) {
+ this.key = key;
+ }
+
+ public String getKey() {
+ return key;
+ }
}
<E> IAtomicReference<E> getAtomicReference(String name);
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessId;
import org.sonar.process.ProcessProperties;
import org.sonar.process.cluster.NodeType;
.setProperty("hazelcast.logging.type", "slf4j");
MemberAttributeConfig attributes = config.getMemberAttributeConfig();
- attributes.setStringAttribute(Attribute.HOSTNAME, NetworkUtils.INSTANCE.getHostname());
- attributes.setStringAttribute(Attribute.IP_ADDRESSES, NetworkUtils.INSTANCE.getIPAddresses());
- attributes.setStringAttribute(Attribute.NODE_NAME, requireNonNull(nodeName, "Node name is missing"));
- attributes.setStringAttribute(Attribute.NODE_TYPE, requireNonNull(nodeType, "Node type is missing").getValue());
- attributes.setStringAttribute(Attribute.PROCESS_KEY, requireNonNull(processId, "Process key is missing").getKey());
+ attributes.setStringAttribute(Attribute.HOSTNAME.getKey(), NetworkUtilsImpl.INSTANCE.getHostname());
+ attributes.setStringAttribute(Attribute.IP_ADDRESSES.getKey(), NetworkUtilsImpl.INSTANCE.getIPAddresses());
+ attributes.setStringAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing"));
+ attributes.setStringAttribute(Attribute.NODE_TYPE.getKey(), requireNonNull(nodeType, "Node type is missing").getValue());
+ attributes.setStringAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey());
return new HazelcastMemberImpl(Hazelcast.newHazelcastInstance(config));
}
import static java.util.Arrays.asList;
import static org.sonar.process.ProcessId.fromKey;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.PROCESS_KEY;
public class HazelcastMemberSelectors {
public static MemberSelector selectorForProcessIds(ProcessId... processIds) {
List<ProcessId> processIdList = asList(processIds);
return member -> {
- ProcessId memberProcessId = fromKey(member.getStringAttribute(HazelcastMember.Attribute.PROCESS_KEY));
+ ProcessId memberProcessId = fromKey(member.getStringAttribute(PROCESS_KEY.getKey()));
return processIdList.contains(memberProcessId);
};
}
package org.sonar.process.cluster.hz;
-import org.sonar.process.ProcessId;
-import org.sonar.process.cluster.NodeType;
-
/**
* This class holds all object keys accessible via Hazelcast
*/
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME;
public class DistributedAnswerTest {
private static Member newMember(String uuid) {
Member member = mock(Member.class);
when(member.getUuid()).thenReturn(uuid);
- when(member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME)).thenReturn(uuid);
+ when(member.getStringAttribute(NODE_NAME.getKey())).thenReturn(uuid);
return member;
}
}
import org.junit.rules.DisableOnDebug;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessId;
import org.sonar.process.ProcessProperties;
import org.sonar.process.cluster.NodeType;
.setProcessId(ProcessId.COMPUTE_ENGINE)
.setClusterName("foo")
.setNodeName("bar")
- .setPort(NetworkUtils.INSTANCE.getNextAvailablePort(loopback))
+ .setPort(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback))
.setNetworkInterface(loopback.getHostAddress())
.build();
import org.junit.rules.ExpectedException;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.ProcessId;
import org.sonar.process.cluster.NodeType;
@BeforeClass
public static void setUp() throws Exception {
- int port1 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback);
- int port2 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback);
- int port3 = NetworkUtils.INSTANCE.getNextAvailablePort(loopback);
+ int port1 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback);
+ int port2 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback);
+ int port3 = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(loopback);
member1 = newHzMember(port1, port2, port3);
member2 = newHzMember(port2, port1, port3);
member3 = newHzMember(port3, port1, port2);
Member member = mock(Member.class);
MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(COMPUTE_ENGINE);
- when(member.getStringAttribute(PROCESS_KEY)).thenReturn(COMPUTE_ENGINE.getKey());
+ when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey());
assertThat(underTest.select(member)).isTrue();
- when(member.getStringAttribute(PROCESS_KEY)).thenReturn(WEB_SERVER.getKey());
+ when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey());
assertThat(underTest.select(member)).isFalse();
- when(member.getStringAttribute(PROCESS_KEY)).thenReturn(APP.getKey());
+ when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
assertThat(underTest.select(member)).isFalse();
}
Member member = mock(Member.class);
MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(WEB_SERVER, APP);
- when(member.getStringAttribute(PROCESS_KEY)).thenReturn(COMPUTE_ENGINE.getKey());
+ when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey());
assertThat(underTest.select(member)).isFalse();
- when(member.getStringAttribute(PROCESS_KEY)).thenReturn(WEB_SERVER.getKey());
+ when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey());
assertThat(underTest.select(member)).isTrue();
- when(member.getStringAttribute(PROCESS_KEY)).thenReturn(APP.getKey());
+ when(member.getStringAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
assertThat(underTest.select(member)).isTrue();
}
}
\ No newline at end of file
public class ServerLogging implements Startable {
/** Used for Hazelcast's distributed queries in cluster mode */
- private static ServerLogging INSTANCE;
+ private static ServerLogging instance;
private final LogbackHelper helper;
private final Configuration config;
private final ServerProcessLogging serverProcessLogging;
@Override
public void start() {
- INSTANCE = this;
+ instance = this;
}
@Override
public void stop() {
- INSTANCE = null;
+ instance = null;
}
public static void changeLevelFromHazelcastDistributedQuery(LoggerLevel level) {
- INSTANCE.changeLevel(level);
+ instance.changeLevel(level);
}
public void changeLevel(LoggerLevel level) {
package org.sonar.server.platform.monitoring;
import java.io.File;
-import org.sonar.api.platform.Server;
import org.sonar.api.server.ServerSide;
+import org.sonar.server.platform.ServerFileSystem;
@ServerSide
public class OfficialDistribution {
static final String BRANDING_FILE_PATH = "web/WEB-INF/classes/com/sonarsource/branding";
- private final Server server;
+ private final ServerFileSystem serverFileSystem;
- public OfficialDistribution(Server server) {
- this.server = server;
+ public OfficialDistribution(ServerFileSystem serverFileSystem) {
+ this.serverFileSystem = serverFileSystem;
}
public boolean check() {
// the dependency com.sonarsource:sonarsource-branding is shaded to webapp
// during release (see sonar-web pom)
- File brandingFile = new File(server.getRootDir(), BRANDING_FILE_PATH);
+ File brandingFile = new File(serverFileSystem.getHomeDir(), BRANDING_FILE_PATH);
// no need to check that the file exists. java.io.File#length() returns zero in this case.
return brandingFile.length() > 0L;
}
import org.sonar.process.cluster.hz.HazelcastMember;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.NODE_NAME;
+import static org.sonar.process.cluster.hz.HazelcastMember.Attribute.PROCESS_KEY;
+
@ServerSide
public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader {
Map<String, NodeInfo> nodesByName = new HashMap<>();
DistributedAnswer<ProtobufSystemInfo.SystemInfo> distributedAnswer = hzMember.call(ProcessInfoProvider::provide, new CeWebMemberSelector(), 15_000L);
for (Member member : distributedAnswer.getMembers()) {
- String nodeName = member.getStringAttribute(HazelcastMember.Attribute.NODE_NAME);
+ String nodeName = member.getStringAttribute(NODE_NAME.getKey());
NodeInfo nodeInfo = nodesByName.get(nodeName);
if (nodeInfo == null) {
nodeInfo = new NodeInfo(nodeName);
private static class CeWebMemberSelector implements MemberSelector {
@Override
public boolean select(Member member) {
- String processKey = member.getStringAttribute(HazelcastMember.Attribute.PROCESS_KEY);
+ String processKey = member.getStringAttribute(PROCESS_KEY.getKey());
return processKey.equals(ProcessId.WEB_SERVER.getKey()) || processKey.equals(ProcessId.COMPUTE_ENGINE.getKey());
}
}
public class ProcessInfoProvider implements Startable {
/** Used for Hazelcast's distributed queries in cluster mode */
- private static ProcessInfoProvider INSTANCE;
+ private static ProcessInfoProvider instance;
private final List<SystemInfoSection> sections;
public ProcessInfoProvider(SystemInfoSection[] sections) {
@Override
public void start() {
- INSTANCE = this;
+ instance = this;
}
@Override
public void stop() {
- INSTANCE = null;
+ instance = null;
}
public static ProtobufSystemInfo.SystemInfo provide() {
ProtobufSystemInfo.SystemInfo.Builder protobuf = ProtobufSystemInfo.SystemInfo.newBuilder();
- INSTANCE.sections.forEach(section -> protobuf.addSections(section.toProtobuf()));
+ instance.sections.forEach(section -> protobuf.addSections(section.toProtobuf()));
return protobuf.build();
}
}
import java.time.Clock;
import java.util.Properties;
import javax.annotation.Nullable;
-import org.sonar.process.NetworkUtils;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarQubeVersion;
import org.sonar.api.internal.ApiVersion;
import org.sonar.db.DefaultDatabase;
import org.sonar.db.purge.PurgeProfiler;
import org.sonar.db.semaphore.SemaphoresImpl;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.logging.LogbackHelper;
import org.sonar.server.app.ProcessCommandWrapperImpl;
import org.sonar.server.app.RestartFlagHolderImpl;
ProcessCommandWrapperImpl.class,
RestartFlagHolderImpl.class,
UuidFactoryImpl.INSTANCE,
- NetworkUtils.INSTANCE,
+ NetworkUtilsImpl.INSTANCE,
UrlSettings.class,
EmbeddedDatabaseFactory.class,
LogbackHelper.class,
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.Props;
import static org.assertj.core.api.Assertions.assertThat;
// start server on a random port
InetAddress address = InetAddress.getLoopbackAddress();
- int httpPort = NetworkUtils.INSTANCE.getNextAvailablePort(address);
+ int httpPort = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(address);
props.set("sonar.web.host", address.getHostAddress());
props.set("sonar.web.port", String.valueOf(httpPort));
EmbeddedTomcat tomcat = new EmbeddedTomcat(props);
import org.junit.rules.ExpectedException;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
@Test
public void start_initializes_hazelcast() {
completeValidSettings();
- StartableHazelcastMember underTest = new StartableHazelcastMember(settings.asConfig(), NetworkUtils.INSTANCE);
+ StartableHazelcastMember underTest = new StartableHazelcastMember(settings.asConfig(), NetworkUtilsImpl.INSTANCE);
verifyStopped(underTest);
underTest.start();
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import static junit.framework.Assert.fail;
import static org.mockito.Mockito.mock;
@Test
public void start_ignores_URL_to_create_database_and_uses_default_username_and_password_when_then_are_not_set() throws IOException {
- int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+ int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
settings
.setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath())
.setProperty(PROP_URL, "jdbc url")
@Test
public void start_creates_db_and_adds_tcp_listener() throws IOException {
- int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+ int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
settings
.setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath())
.setProperty(PROP_URL, "jdbc url")
@Test
public void start_supports_in_memory_H2_JDBC_URL() throws IOException {
- int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+ int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
settings
.setProperty(PATH_DATA, temporaryFolder.newFolder().getAbsolutePath())
.setProperty(PROP_URL, "jdbc:h2:mem:sonar")
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.platform.Server;
+import org.sonar.server.platform.ServerFileSystem;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- private Server server = mock(Server.class);
- private OfficialDistribution underTest = new OfficialDistribution(server);
+ private ServerFileSystem serverFileSystem = mock(ServerFileSystem.class);
+ private OfficialDistribution underTest = new OfficialDistribution(serverFileSystem);
@Test
public void official_distribution() throws Exception {
File rootDir = temp.newFolder();
FileUtils.write(new File(rootDir, OfficialDistribution.BRANDING_FILE_PATH), "1.2");
- when(server.getRootDir()).thenReturn(rootDir);
+ when(serverFileSystem.getHomeDir()).thenReturn(rootDir);
assertThat(underTest.check()).isTrue();
}
public void not_an_official_distribution() throws Exception {
File rootDir = temp.newFolder();
// branding file is missing
- when(server.getRootDir()).thenReturn(rootDir);
+ when(serverFileSystem.getHomeDir()).thenReturn(rootDir);
assertThat(underTest.check()).isFalse();
}
import java.net.InetAddress;
import java.util.Collections;
import org.jboss.byteman.agent.submit.Submit;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import static java.lang.String.format;
public Byteman(OrchestratorBuilder builder, Process process) {
this.builder = builder;
String jar = findBytemanJar();
- port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+ port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
String bytemanArg = format("-javaagent:%s=boot:%s,port:%d", jar, jar, port);
builder.setServerProperty(process.argument, bytemanArg);
}
import java.net.InetAddress;
import okhttp3.HttpUrl;
import org.junit.Test;
-import org.sonar.process.NetworkUtils;
+import org.sonar.process.NetworkUtilsImpl;
import static org.assertj.core.api.Assertions.assertThat;
@Test
public void set_http_port_through_sonar_properties() throws Exception {
- int port = NetworkUtils.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
+ int port = NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getLoopbackAddress());
Orchestrator orchestrator = Orchestrator
.builderEnv()
.setServerProperty("sonar.search.httpPort", "" + port)