diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 387f03f88f8..7307dbb8881 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -434,8 +434,8 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I } @Override - public List getTransportInterceptors() { - return security.getTransportInterceptors(); + public List getTransportInterceptors(NamedWriteableRegistry namedWriteableRegistry) { + return security.getTransportInterceptors(namedWriteableRegistry); } @Override diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/Security.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/Security.java index 5ee97e6a428..97cfc95db9e 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -677,7 +677,7 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin { } @Override - public List getTransportInterceptors() { + public List getTransportInterceptors(NamedWriteableRegistry namedWriteableRegistry) { if (transportClientMode || enabled == false) { // don't register anything if we are not enabled // interceptors are not installed if we are running on the transport client return Collections.emptyList(); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrail.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrail.java index aacfc8c1ee7..91566eaf572 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrail.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrail.java @@ -36,7 +36,6 @@ import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AbstractRunnable; @@ -707,12 +706,8 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl TransportAddress address = message.remoteAddress(); if (address != null) { builder.field(Field.ORIGIN_TYPE, "transport"); - if (address instanceof InetSocketTransportAddress) { - builder.field(Field.ORIGIN_ADDRESS, - NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress())); - } else { - builder.field(Field.ORIGIN_ADDRESS, address); - } + builder.field(Field.ORIGIN_ADDRESS, + NetworkAddress.format(address.address().getAddress())); return builder; } @@ -771,7 +766,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl .put(theClientSetting).build(), Settings.EMPTY, Collections.singletonList(XPackPlugin.class)) {}; for (Tuple pair : hostPortPairs) { try { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(pair.v1()), pair.v2())); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName(pair.v1()), pair.v2())); } catch (UnknownHostException e) { throw new ElasticsearchException("could not find host {}", e, pair.v1()); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrail.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrail.java index 0fb877c1445..d21a9230bc4 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrail.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrail.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.rest.RestRequest; @@ -408,13 +407,9 @@ public class LoggingAuditTrail extends AbstractComponent implements AuditTrail { TransportAddress address = message.remoteAddress(); if (address != null) { builder.append("origin_type=[transport], "); - if (address instanceof InetSocketTransportAddress) { - builder.append("origin_address=["). - append(NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress())). + builder.append("origin_address=["). + append(NetworkAddress.format(address.address().getAddress())). append("]"); - } else { - builder.append("origin_address=[").append(address).append("]"); - } return builder.toString(); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/transport/filter/SecurityIpFilterRule.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/transport/filter/SecurityIpFilterRule.java index d6d26be45be..adbafe663f5 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/transport/filter/SecurityIpFilterRule.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/transport/filter/SecurityIpFilterRule.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.security.transport.filter; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.network.InetAddresses; import org.elasticsearch.common.network.NetworkAddress; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.jboss.netty.handler.ipfilter.IpFilterRule; import org.jboss.netty.handler.ipfilter.IpSubnetFilterRule; @@ -154,8 +153,7 @@ public class SecurityIpFilterRule implements IpFilterRule { firstAdded = true; } - assert transportAddress instanceof InetSocketTransportAddress; - ruleSpec.append(NetworkAddress.format(((InetSocketTransportAddress) transportAddress).address().getAddress())); + ruleSpec.append(NetworkAddress.format(transportAddress.address().getAddress())); } return ruleSpec.toString(); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java index 9e44915ddd5..99220255f7d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java @@ -64,7 +64,7 @@ public class ExecutionService extends AbstractComponent { private final TimeValue maxStopTimeout; private final ThreadPool threadPool; - private volatile CurrentExecutions currentExecutions = null; + private volatile CurrentExecutions currentExecutions; private final AtomicBoolean started = new AtomicBoolean(false); @Inject diff --git a/elasticsearch/src/test/java/org/elasticsearch/license/AbstractLicenseServiceTestCase.java b/elasticsearch/src/test/java/org/elasticsearch/license/AbstractLicenseServiceTestCase.java index 7f3e247db92..7c178c58f46 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/license/AbstractLicenseServiceTestCase.java +++ b/elasticsearch/src/test/java/org/elasticsearch/license/AbstractLicenseServiceTestCase.java @@ -15,7 +15,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.component.Lifecycle; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.env.Environment; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.ResourceWatcherService; @@ -59,7 +58,7 @@ public abstract class AbstractLicenseServiceTestCase extends ESTestCase { MetaData metaData = mock(MetaData.class); when(metaData.custom(LicensesMetaData.TYPE)).thenReturn(new LicensesMetaData(license)); when(state.metaData()).thenReturn(metaData); - final DiscoveryNode mockNode = new DiscoveryNode("b", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT); + final DiscoveryNode mockNode = new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); when(discoveryNodes.getMasterNode()).thenReturn(mockNode); when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(false); when(state.nodes()).thenReturn(discoveryNodes); diff --git a/elasticsearch/src/test/java/org/elasticsearch/license/LicenseClusterChangeTests.java b/elasticsearch/src/test/java/org/elasticsearch/license/LicenseClusterChangeTests.java index abf927ea012..451f7001d47 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/license/LicenseClusterChangeTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/license/LicenseClusterChangeTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.junit.After; import org.junit.Before; @@ -64,7 +63,7 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase { } public void testTrialLicenseGeneration() throws Exception { - DiscoveryNode master = new DiscoveryNode("b", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode master = new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); ClusterState oldState = ClusterState.builder(new ClusterName("a")) .nodes(DiscoveryNodes.builder().masterNodeId(master.getId()).add(master)).build(); when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true); diff --git a/elasticsearch/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java b/elasticsearch/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java index 69154a2edb9..ad924612e49 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java +++ b/elasticsearch/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java @@ -21,6 +21,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; +import org.elasticsearch.node.MockNode; +import org.elasticsearch.transport.MockTcpTransportPlugin; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.node.Node; @@ -54,7 +56,7 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { protected final Settings nodeSettings(int nodeOrdinal) { final Settings.Builder builder = Settings.builder() .put(NetworkModule.HTTP_ENABLED.getKey(), false) - .put("transport.type", "local") + .put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME) .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local"); List enabledFeatures = enabledFeatures(); builder.put(XPackSettings.SECURITY_ENABLED.getKey(), enabledFeatures.contains(XPackPlugin.SECURITY)); @@ -128,8 +130,8 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { Settings merged = Settings.builder() .put("tribe.t1.cluster.name", internalCluster().getClusterName()) .put("tribe.t2.cluster.name", cluster2.getClusterName()) - .put("tribe.t1.transport.type", "local") - .put("tribe.t2.transport.type", "local") + .put("tribe.t1.transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME) + .put("tribe.t2.transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME) .put("tribe.t1.discovery.type", "local") .put("tribe.t2.discovery.type", "local") .put("tribe.blocks.write", false) @@ -138,10 +140,10 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { .put(NetworkModule.HTTP_ENABLED.getKey(), false) .put(internalCluster().getDefaultSettings()) .put("node.name", "tribe_node") // make sure we can identify threads from this node - .put("transport.type", "local") + .put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME) .build(); - final Node tribeNode = new Node(merged).start(); + final Node tribeNode = new MockNode(merged, Collections.singleton(MockTcpTransportPlugin.class)).start(); Client tribeClient = tribeNode.client(); logger.info("wait till tribe has the same nodes as the 2 clusters"); diff --git a/elasticsearch/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java b/elasticsearch/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java index 20f1015fcec..0bfaf3d10f6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java +++ b/elasticsearch/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java @@ -14,7 +14,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.xpack.XPackSettings; @@ -22,7 +21,6 @@ import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.client.SecurityClient; -import org.elasticsearch.test.ESIntegTestCase.SuppressLocalMode; import org.elasticsearch.xpack.XPackClient; import org.elasticsearch.xpack.XPackPlugin; import org.junit.AfterClass; @@ -51,7 +49,6 @@ import static org.hamcrest.core.IsCollectionContaining.hasItem; * * @see SecuritySettingsSource */ -@SuppressLocalMode public abstract class SecurityIntegTestCase extends ESIntegTestCase { private static SecuritySettingsSource SECURITY_DEFAULT_SETTINGS; @@ -394,8 +391,7 @@ public abstract class SecurityIntegTestCase extends ESIntegTestCase { NodeInfo ni = randomFrom(nodes); boolean useSSL = XPackSettings.HTTP_SSL_ENABLED.get(ni.getSettings()); TransportAddress publishAddress = ni.getHttp().address().publishAddress(); - assertEquals(1, publishAddress.uniqueAddressTypeId()); - InetSocketAddress address = ((InetSocketTransportAddress) publishAddress).address(); + InetSocketAddress address = publishAddress.address(); return (useSSL ? "https://" : "http://") + NetworkAddress.format(address.getAddress()) + ":" + address.getPort(); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/TestXPackTransportClient.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/TestXPackTransportClient.java index 7a7175bf016..d5215fd795a 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/TestXPackTransportClient.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/TestXPackTransportClient.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.transport.MockTcpTransportPlugin; import java.util.Arrays; import java.util.Collection; @@ -24,6 +25,6 @@ public class TestXPackTransportClient extends TransportClient { } public TestXPackTransportClient(Settings settings, Collection> plugins) { - super(settings, Settings.EMPTY, addPlugins(plugins, XPackPlugin.class)); + super(settings, Settings.EMPTY, addPlugins(plugins, XPackPlugin.class, MockTcpTransportPlugin.class)); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/OldMonitoringIndicesBackwardsCompatibilityIT.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/OldMonitoringIndicesBackwardsCompatibilityIT.java index e2c1afd5da2..3d3ba19394e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/OldMonitoringIndicesBackwardsCompatibilityIT.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/OldMonitoringIndicesBackwardsCompatibilityIT.java @@ -11,7 +11,6 @@ import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.IndexNotFoundException; @@ -91,8 +90,7 @@ public class OldMonitoringIndicesBackwardsCompatibilityIT extends AbstractOldXPa // If we're using the http exporter we need feed it the port and enable it NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get(); TransportAddress publishAddress = nodeInfos.getNodes().get(0).getHttp().address().publishAddress(); - assertEquals(1, publishAddress.uniqueAddressTypeId()); - InetSocketAddress address = ((InetSocketTransportAddress) publishAddress).address(); + InetSocketAddress address = publishAddress.address(); Settings.Builder settings = Settings.builder(); setupHttpExporter(settings, address.getPort()); client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings).get(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java index d8856d6dcf1..a9a59953d4a 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java @@ -20,7 +20,6 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.test.ESTestCase; @@ -96,7 +95,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase { clusterService = new ClusterService(Settings.builder().put("cluster.name", TransportMonitoringBulkActionTests.class.getName()).build(), new ClusterSettings(Settings.EMPTY, clusterSettings), threadPool); - clusterService.setLocalNode(new DiscoveryNode("node", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), + clusterService.setLocalNode(new DiscoveryNode("node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) { @Override diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/MonitoringDocTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/MonitoringDocTests.java index 6fa1661f74e..d3bf847f7fa 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/MonitoringDocTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/MonitoringDocTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -130,7 +129,7 @@ public class MonitoringDocTests extends ESTestCase { } } Set roles = new HashSet<>(randomSubsetOf(Arrays.asList(DiscoveryNode.Role.values()))); - return new DiscoveryNode(randomAsciiOfLength(5), randomAsciiOfLength(3), LocalTransportAddress.buildUnique(), + return new DiscoveryNode(randomAsciiOfLength(5), randomAsciiOfLength(3), buildNewFakeTransportAddress(), attributes, roles, randomVersion(random())); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java index aae545498d0..ff4941b962f 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; @@ -495,14 +494,14 @@ public class HttpExporterIT extends MonitoringIntegTestCase { IndexRecoveryMonitoringDoc doc = new IndexRecoveryMonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString()); doc.setClusterUUID(internalCluster().getClusterName()); doc.setTimestamp(System.currentTimeMillis()); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setRecoveryResponse(new RecoveryResponse()); return doc; } else { ClusterStateMonitoringDoc doc = new ClusterStateMonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString()); doc.setClusterUUID(internalCluster().getClusterName()); doc.setTimestamp(System.currentTimeMillis()); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setClusterState(ClusterState.PROTO); doc.setStatus(ClusterHealthStatus.GREEN); return doc; diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java index fe089d90833..8c889830c87 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; @@ -198,14 +197,14 @@ public class LocalExporterTests extends MonitoringIntegTestCase { IndexRecoveryMonitoringDoc doc = new IndexRecoveryMonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString()); doc.setClusterUUID(internalCluster().getClusterName()); doc.setTimestamp(System.currentTimeMillis()); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setRecoveryResponse(new RecoveryResponse()); return doc; } else { ClusterStateMonitoringDoc doc = new ClusterStateMonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString()); doc.setClusterUUID(internalCluster().getClusterName()); doc.setTimestamp(System.currentTimeMillis()); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setClusterState(ClusterState.PROTO); doc.setStatus(ClusterHealthStatus.GREEN); return doc; diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/DataResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/DataResolverTests.java index 868d8cd0ce2..fe547768dde 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/DataResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/DataResolverTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.monitoring.resolver; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc; @@ -31,7 +30,7 @@ public class DataResolverTests extends MonitoringIndexNameResolverTestCase { MonitoringDoc doc = new MonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); return doc; } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/TimestampedResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/TimestampedResolverTests.java index 1c529006482..4dbbf6ebb4c 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/TimestampedResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/TimestampedResolverTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.monitoring.resolver; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.monitoring.MonitoredSystem; @@ -40,7 +39,7 @@ public class TimestampedResolverTests extends MonitoringIndexNameResolverTestCas MonitoringDoc doc = new MonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode(randomAsciiOfLength(5), LocalTransportAddress.buildUnique(), + doc.setSourceNode(new DiscoveryNode(randomAsciiOfLength(5), buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); return doc; } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/bulk/MonitoringBulkDataResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/bulk/MonitoringBulkDataResolverTests.java index dc25700206f..1857c2c8e91 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/bulk/MonitoringBulkDataResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/bulk/MonitoringBulkDataResolverTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.monitoring.resolver.bulk; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.xpack.monitoring.MonitoredSystem; @@ -41,7 +40,7 @@ public class MonitoringBulkDataResolverTests extends MonitoringIndexNameResolver doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); return doc; } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/bulk/MonitoringBulkTimestampedResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/bulk/MonitoringBulkTimestampedResolverTests.java index 862eaf8f062..9e10cf17441 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/bulk/MonitoringBulkTimestampedResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/bulk/MonitoringBulkTimestampedResolverTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.monitoring.resolver.bulk; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.xpack.monitoring.MonitoredSystem; @@ -43,7 +42,7 @@ public class MonitoringBulkTimestampedResolverTests } doc.setClusterUUID(randomAsciiOfLength(5)); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); return doc; } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterInfoResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterInfoResolverTests.java index 403023a0ecd..1a266d281bf 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterInfoResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterInfoResolverTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; @@ -44,7 +43,7 @@ public class ClusterInfoResolverTests extends MonitoringIndexNameResolverTestCas ClusterInfoMonitoringDoc doc = new ClusterInfoMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setVersion(randomFrom(Version.V_2_0_0, Version.CURRENT).toString()); doc.setLicense(licenseBuilder.build()); doc.setClusterName(randomAsciiOfLength(5)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStateNodeResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStateNodeResolverTests.java index 06653d4eb48..0b82d9491f0 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStateNodeResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStateNodeResolverTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.monitoring.resolver.cluster; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStateNodeMonitoringDoc; @@ -29,7 +28,7 @@ public class ClusterStateNodeResolverTests extends ClusterStateNodeMonitoringDoc doc = new ClusterStateNodeMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setNodeId(UUID.randomUUID().toString()); doc.setStateUUID(UUID.randomUUID().toString()); return doc; diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStateResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStateResolverTests.java index c16e78f1e38..54cd5d6e6d2 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStateResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStateResolverTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStateMonitoringDoc; @@ -32,12 +31,12 @@ public class ClusterStateResolverTests extends MonitoringIndexNameResolverTestCa ClusterStateMonitoringDoc doc = new ClusterStateMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setStatus(randomFrom(ClusterHealthStatus.values())); - DiscoveryNode masterNode = new DiscoveryNode("master", new LocalTransportAddress("master"), + DiscoveryNode masterNode = new DiscoveryNode("master", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); - DiscoveryNode otherNode = new DiscoveryNode("other", new LocalTransportAddress("other"), emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode otherNode = new DiscoveryNode("other", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(masterNode).add(otherNode).masterNodeId(masterNode.getId()).build(); ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(discoveryNodes).build(); doc.setClusterState(clusterState); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStatsResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStatsResolverTests.java index 380f8ade03f..116ae651fee 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStatsResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/cluster/ClusterStatsResolverTests.java @@ -22,7 +22,6 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.BoundTransportAddress; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.util.set.Sets; @@ -65,7 +64,7 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa ClusterStatsMonitoringDoc doc = new ClusterStatsMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setClusterStats(randomClusterStats()); return doc; } @@ -97,7 +96,7 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa */ private ClusterStatsResponse randomClusterStats() { List responses = Collections.singletonList( - new ClusterStatsNodeResponse(new DiscoveryNode("node_0", LocalTransportAddress.buildUnique(), + new ClusterStatsNodeResponse(new DiscoveryNode("node_0", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), ClusterHealthStatus.GREEN, randomNodeInfo(), randomNodeStats(), randomShardStats()) ); @@ -109,10 +108,10 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa * @return a random {@link NodeInfo} used to resolve a monitoring document. */ private NodeInfo randomNodeInfo() { - BoundTransportAddress transportAddress = new BoundTransportAddress(new TransportAddress[]{LocalTransportAddress.buildUnique()}, - LocalTransportAddress.buildUnique()); + BoundTransportAddress transportAddress = new BoundTransportAddress(new TransportAddress[]{buildNewFakeTransportAddress()}, + buildNewFakeTransportAddress()); return new NodeInfo(Version.CURRENT, org.elasticsearch.Build.CURRENT, - new DiscoveryNode("node_0", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT), Settings.EMPTY, + new DiscoveryNode("node_0", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), Settings.EMPTY, DummyOsInfo.INSTANCE, new ProcessInfo(randomInt(), randomBoolean(), randomPositiveLong()), JvmInfo.jvmInfo(), new ThreadPoolInfo(Collections.singletonList(new ThreadPool.Info("test_threadpool", ThreadPool.ThreadPoolType.FIXED, 5))), new TransportInfo(transportAddress, Collections.emptyMap()), new HttpInfo(transportAddress, randomLong()), @@ -131,7 +130,7 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa }; Map> statsByShard = new HashMap<>(); statsByShard.put(index, Collections.singletonList(new IndexShardStats(new ShardId(index, 0), randomShardStats()))); - return new NodeStats(new DiscoveryNode("node_0", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT), 0, + return new NodeStats(new DiscoveryNode("node_0", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), 0, new NodeIndicesStats(new CommonStats(), statsByShard), null, null, null, null, new FsInfo(0, null, pathInfo), null, null, null, null, null, null); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndexRecoveryResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndexRecoveryResolverTests.java index 1b12b8b9dfb..819daea504d 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndexRecoveryResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndexRecoveryResolverTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.TestShardRouting; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.shard.ShardId; @@ -37,9 +36,9 @@ public class IndexRecoveryResolverTests extends MonitoringIndexNameResolverTestC IndexRecoveryMonitoringDoc doc = new IndexRecoveryMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); - DiscoveryNode localNode = new DiscoveryNode("foo", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); Map> shardRecoveryStates = new HashMap<>(); ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId("test", "uuid", 0), localNode.getId(), true, ShardRoutingState.INITIALIZING, RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndexStatsResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndexStatsResolverTests.java index 6dfbb0098f3..866f9c0baf2 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndexStatsResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndexStatsResolverTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.Index; @@ -48,7 +47,7 @@ public class IndexStatsResolverTests extends MonitoringIndexNameResolverTestCase IndexStatsMonitoringDoc doc = new IndexStatsMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setIndexStats(randomIndexStats()); return doc; } @@ -61,7 +60,7 @@ public class IndexStatsResolverTests extends MonitoringIndexNameResolverTestCase public void testIndexStatsResolver() throws Exception { IndexStatsMonitoringDoc doc = newMonitoringDoc(); doc.setTimestamp(1437580442979L); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); IndexStatsResolver resolver = newResolver(); assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22")); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndicesStatsResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndicesStatsResolverTests.java index 2b17a40f000..7d05b38afa1 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndicesStatsResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/indices/IndicesStatsResolverTests.java @@ -14,7 +14,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.Index; @@ -51,7 +50,7 @@ public class IndicesStatsResolverTests extends MonitoringIndexNameResolverTestCa IndicesStatsMonitoringDoc doc = new IndicesStatsMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setIndicesStats(randomIndicesStats()); return doc; } @@ -65,7 +64,7 @@ public class IndicesStatsResolverTests extends MonitoringIndexNameResolverTestCa IndicesStatsMonitoringDoc doc = newMonitoringDoc(); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(1437580442979L); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); IndicesStatsResolver resolver = newResolver(); assertThat(resolver.index(doc), equalTo(".monitoring-es-" + MonitoringTemplateUtils.TEMPLATE_VERSION + "-2015.07.22")); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/DiscoveryNodeResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/DiscoveryNodeResolverTests.java index 196ab26f147..81368f26347 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/DiscoveryNodeResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/DiscoveryNodeResolverTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.monitoring.resolver.node; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.VersionUtils; @@ -29,9 +28,9 @@ public class DiscoveryNodeResolverTests extends MonitoringIndexNameResolverTestC DiscoveryNodeMonitoringDoc doc = new DiscoveryNodeMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setNode(new DiscoveryNode(randomAsciiOfLength(3), UUID.randomUUID().toString(), - LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), + buildNewFakeTransportAddress(), emptyMap(), emptySet(), VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), Version.CURRENT))); return doc; } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/NodeStatsResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/NodeStatsResolverTests.java index b6539a633d2..8d56a7743cc 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/NodeStatsResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/NodeStatsResolverTests.java @@ -16,7 +16,6 @@ import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.Index; @@ -63,7 +62,7 @@ public class NodeStatsResolverTests extends MonitoringIndexNameResolverTestCase< NodeStatsMonitoringDoc doc = new NodeStatsMonitoringDoc(randomMonitoringId(), randomAsciiOfLength(2)); doc.setClusterUUID(randomAsciiOfLength(5)); doc.setTimestamp(Math.abs(randomLong())); - doc.setSourceNode(new DiscoveryNode("id", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT)); + doc.setSourceNode(new DiscoveryNode("id", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); doc.setNodeMaster(randomBoolean()); doc.setNodeId(UUID.randomUUID().toString()); doc.setMlockall(randomBoolean()); @@ -150,7 +149,7 @@ public class NodeStatsResolverTests extends MonitoringIndexNameResolverTestCase< new ThreadPoolStats.Stats(ThreadPool.Names.SEARCH, 0, 0, 0, 0, 0, 0), new ThreadPoolStats.Stats(InternalWatchExecutor.THREAD_POOL_NAME, 0, 0, 0, 0, 0, 0) ); - return new NodeStats(new DiscoveryNode("node_0", LocalTransportAddress.buildUnique(), emptyMap(), emptySet(), Version.CURRENT), 0, + return new NodeStats(new DiscoveryNode("node_0", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT), 0, new NodeIndicesStats(new CommonStats(), statsByShard), OsProbe.getInstance().osStats(), ProcessProbe.getInstance().processStats(), JvmStats.jvmStats(), new ThreadPoolStats(threadPoolStats), diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/shards/ShardsResolverTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/shards/ShardsResolverTests.java index 3e8da67ef18..d077f7ecbe0 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/shards/ShardsResolverTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/shards/ShardsResolverTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.Index; @@ -35,7 +34,7 @@ public class ShardsResolverTests extends MonitoringIndexNameResolverTestCase> getMockPlugins() { Set> plugins = new HashSet<>(super.getMockPlugins()); plugins.remove(MockTransportService.TestPlugin.class); // security has its own transport service - plugins.remove(AssertingLocalTransport.TestPlugin.class); // security has its own transport plugins.add(MockFSIndexStore.TestPlugin.class); return plugins; } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/SecurityTemplateServiceTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/SecurityTemplateServiceTests.java index 433a4412630..0abab7137f8 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/SecurityTemplateServiceTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/SecurityTemplateServiceTests.java @@ -28,7 +28,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; @@ -62,7 +61,7 @@ public class SecurityTemplateServiceTests extends ESTestCase { @Before public void setup() { DiscoveryNode localNode = mock(DiscoveryNode.class); - when(localNode.getHostAddress()).thenReturn(LocalTransportAddress.buildUnique().toString()); + when(localNode.getHostAddress()).thenReturn(buildNewFakeTransportAddress().toString()); clusterService = mock(ClusterService.class); when(clusterService.localNode()).thenReturn(localNode); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java index a53185305ab..de035afa282 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java @@ -20,7 +20,6 @@ import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; @@ -55,7 +54,7 @@ public class IndexAuditTrailMutedTests extends ESTestCase { @Before public void setup() { DiscoveryNode localNode = mock(DiscoveryNode.class); - when(localNode.getHostAddress()).thenReturn(LocalTransportAddress.buildUnique().toString()); + when(localNode.getHostAddress()).thenReturn(buildNewFakeTransportAddress().toString()); clusterService = mock(ClusterService.class); when(clusterService.localNode()).thenReturn(localNode); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java index 16da2780268..93c49327914 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java @@ -32,8 +32,7 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; -import org.elasticsearch.common.transport.LocalTransportAddress; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.search.SearchHit; @@ -77,9 +76,6 @@ import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -/** - * - */ @ESIntegTestCase.ClusterScope(scope = SUITE, supportsDedicatedMasters = false, numDataNodes = 1) public class IndexAuditTrailTests extends SecurityIntegTestCase { public static final String SECOND_CLUSTER_NODE_PREFIX = "remote_" + SUITE_CLUSTER_NODE_PREFIX; @@ -89,6 +85,8 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { private static Settings remoteSettings; private static byte[] systemKey; + private TransportAddress remoteAddress = buildNewFakeTransportAddress(); + private TransportAddress localAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 0); private IndexNameResolver.Rollover rollover; private IndexAuditTrail auditor; private SetOnce enqueuedMessage; @@ -160,7 +158,7 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { NodesInfoResponse response = remoteCluster.client().admin().cluster().prepareNodesInfo().execute().actionGet(); TransportInfo info = response.getNodes().get(0).getTransport(); - InetSocketTransportAddress inet = (InetSocketTransportAddress) info.address().publishAddress(); + TransportAddress inet = info.address().publishAddress(); Settings.Builder builder = Settings.builder() .put(XPackSettings.SECURITY_ENABLED.getKey(), useSecurity) @@ -266,8 +264,8 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { Settings settings = builder.put(settings(rollover, includes, excludes)).build(); logger.info("--> settings: [{}]", settings.getAsMap().toString()); DiscoveryNode localNode = mock(DiscoveryNode.class); - when(localNode.getHostAddress()).thenReturn(remoteHostAddress().getAddress()); - when(localNode.getHostName()).thenReturn(remoteHostAddress().getHost()); + when(localNode.getHostAddress()).thenReturn(remoteAddress.getAddress()); + when(localNode.getHostName()).thenReturn(remoteAddress.getHost()); ClusterService clusterService = mock(ClusterService.class); when(clusterService.localNode()).thenReturn(localNode); threadPool = new TestThreadPool("index audit trail tests"); @@ -291,9 +289,9 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { assertAuditMessage(hit, "transport", "anonymous_access_denied"); Map sourceMap = hit.sourceAsMap(); if (message instanceof RemoteHostMockMessage) { - assertEquals(remoteHostAddress().toString(), sourceMap.get("origin_address")); + assertEquals(remoteAddress.getAddress(), sourceMap.get("origin_address")); } else { - assertEquals("local[local_host]", sourceMap.get("origin_address")); + assertEquals(localAddress.getAddress(), sourceMap.get("origin_address")); } assertEquals("_action", sourceMap.get("action")); @@ -328,9 +326,9 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { assertAuditMessage(hit, "transport", "authentication_failed"); if (message instanceof RemoteHostMockMessage) { - assertEquals(remoteHostAddress().toString(), sourceMap.get("origin_address")); + assertEquals(remoteAddress.getAddress(), sourceMap.get("origin_address")); } else { - assertEquals("local[local_host]", sourceMap.get("origin_address")); + assertEquals(localAddress.getAddress(), sourceMap.get("origin_address")); } assertEquals("_principal", sourceMap.get("principal")); @@ -348,9 +346,9 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { assertAuditMessage(hit, "transport", "authentication_failed"); Map sourceMap = hit.sourceAsMap(); if (message instanceof RemoteHostMockMessage) { - assertEquals(remoteHostAddress().toString(), sourceMap.get("origin_address")); + assertEquals(remoteAddress.getAddress(), sourceMap.get("origin_address")); } else { - assertEquals("local[local_host]", sourceMap.get("origin_address")); + assertEquals(localAddress.getAddress(), sourceMap.get("origin_address")); } assertThat(sourceMap.get("principal"), nullValue()); @@ -403,9 +401,9 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { Map sourceMap = hit.sourceAsMap(); if (message instanceof RemoteHostMockMessage) { - assertEquals(remoteHostAddress().toString(), sourceMap.get("origin_address")); + assertEquals(remoteAddress.getAddress(), sourceMap.get("origin_address")); } else { - assertEquals("local[local_host]", sourceMap.get("origin_address")); + assertEquals(localAddress.getAddress(), sourceMap.get("origin_address")); } assertEquals("transport", sourceMap.get("origin_type")); @@ -688,8 +686,8 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { DateTime dateTime = ISODateTimeFormat.dateTimeParser().withZoneUTC().parseDateTime((String) sourceMap.get("@timestamp")); assertThat(dateTime.isBefore(DateTime.now(DateTimeZone.UTC)), is(true)); - assertThat(remoteHostAddress().getHost(), equalTo(sourceMap.get("node_host_name"))); - assertThat(remoteHostAddress().getAddress(), equalTo(sourceMap.get("node_host_address"))); + assertThat(remoteAddress.getHost(), equalTo(sourceMap.get("node_host_name"))); + assertThat(remoteAddress.getAddress(), equalTo(sourceMap.get("node_host_address"))); assertEquals(layer, sourceMap.get("layer")); assertEquals(type, sourceMap.get("event_type")); @@ -702,25 +700,25 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { assertThat(sourceMap.get("request_body"), nullValue()); } } - private static class LocalHostMockMessage extends TransportMessage { + private class LocalHostMockMessage extends TransportMessage { LocalHostMockMessage() { - remoteAddress(new LocalTransportAddress("local_host")); + remoteAddress(localAddress); } } - private static class RemoteHostMockMessage extends TransportMessage { + private class RemoteHostMockMessage extends TransportMessage { RemoteHostMockMessage() throws Exception { - remoteAddress(remoteHostAddress()); + remoteAddress(remoteAddress); } } - private static class RemoteHostMockTransportRequest extends TransportRequest { + private class RemoteHostMockTransportRequest extends TransportRequest { RemoteHostMockTransportRequest() throws Exception { - remoteAddress(remoteHostAddress()); + remoteAddress(remoteAddress); } } - private static class MockIndicesTransportMessage extends RemoteHostMockMessage implements IndicesRequest { + private class MockIndicesTransportMessage extends RemoteHostMockMessage implements IndicesRequest { MockIndicesTransportMessage() throws Exception { super(); } @@ -811,9 +809,5 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { logger.debug("indices {} are yellow", indices.length == 0 ? "[_all]" : indices); return actionGet.getStatus(); } - - private static LocalTransportAddress remoteHostAddress() { - return new LocalTransportAddress("_remote_host_"); - } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailUpdateMappingTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailUpdateMappingTests.java index fd2d34296cd..5c30aa5a02f 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailUpdateMappingTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailUpdateMappingTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -47,7 +46,7 @@ public class IndexAuditTrailUpdateMappingTests extends SecurityIntegTestCase { Settings settings = Settings.builder().put("xpack.security.audit.index.rollover", rollover.name().toLowerCase(Locale.ENGLISH)) .put("path.home", createTempDir()).build(); DiscoveryNode localNode = mock(DiscoveryNode.class); - when(localNode.getHostAddress()).thenReturn(LocalTransportAddress.buildUnique().toString()); + when(localNode.getHostAddress()).thenReturn(buildNewFakeTransportAddress().toString()); ClusterService clusterService = mock(ClusterService.class); when(clusterService.localNode()).thenReturn(localNode); auditor = new IndexAuditTrail(settings, internalClient(), threadPool, clusterService); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java index d7eb76e1da1..17397385eb1 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.xpack.security.audit.index; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.InternalTestCluster; @@ -81,7 +81,7 @@ public class RemoteIndexAuditTrailStartingTests extends SecurityIntegTestCase { NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().execute().actionGet(); final String clusterName = response.getClusterName().value(); for (NodeInfo nodeInfo : response.getNodes()) { - InetSocketTransportAddress address = (InetSocketTransportAddress) nodeInfo.getTransport().address().publishAddress(); + TransportAddress address = nodeInfo.getTransport().address().publishAddress(); addresses.add(address.address().getHostString() + ":" + address.address().getPort()); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrailTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrailTests.java index 827a493cd3c..9ca84821de6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrailTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrailTests.java @@ -16,8 +16,6 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; -import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.rest.RestRequest; @@ -119,7 +117,7 @@ public class LoggingAuditTrailTests extends ESTestCase { .put("xpack.security.audit.logfile.events.emit_request_body", includeRequestBody) .build(); localNode = mock(DiscoveryNode.class); - when(localNode.getHostAddress()).thenReturn(LocalTransportAddress.buildUnique().toString()); + when(localNode.getHostAddress()).thenReturn(buildNewFakeTransportAddress().toString()); clusterService = mock(ClusterService.class); when(clusterService.localNode()).thenReturn(localNode); prefix = LoggingAuditTrail.resolvePrefix(settings, localNode); @@ -595,12 +593,8 @@ public class LoggingAuditTrailTests extends ESTestCase { return; } - if (address instanceof InetSocketTransportAddress) { - assertThat(text, equalTo("origin_type=[transport], origin_address=[" + - NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress()) + "]")); - } else { - assertThat(text, equalTo("origin_type=[transport], origin_address=[" + address + "]")); - } + assertThat(text, equalTo("origin_type=[transport], origin_address=[" + + NetworkAddress.format(address.address().getAddress()) + "]")); } public void testAuthenticationSuccessRest() throws Exception { @@ -716,9 +710,9 @@ public class LoggingAuditTrailTests extends ESTestCase { private MockMessage(ThreadContext threadContext) throws IOException { if (randomBoolean()) { if (randomBoolean()) { - remoteAddress(new LocalTransportAddress("local_host")); + remoteAddress(buildNewFakeTransportAddress()); } else { - remoteAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 1234)); + remoteAddress(new TransportAddress(InetAddress.getLoopbackAddress(), 1234)); } } if (randomBoolean()) { @@ -731,7 +725,7 @@ public class LoggingAuditTrailTests extends ESTestCase { private MockIndicesRequest(ThreadContext threadContext) throws IOException { if (randomBoolean()) { - remoteAddress(new LocalTransportAddress("_host")); + remoteAddress(buildNewFakeTransportAddress()); } if (randomBoolean()) { RemoteHostHeader.putRestRemoteAddress(threadContext, new InetSocketAddress(forge("localhost", "127.0.0.1"), 1234)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiAuthenticationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiAuthenticationTests.java index 4052b47eb21..efa52b6dd02 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiAuthenticationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiAuthenticationTests.java @@ -16,7 +16,6 @@ import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.xpack.security.Security; @@ -161,8 +160,6 @@ public class PkiAuthenticationTests extends SecurityIntegTestCase { private String getNodeUrl() { TransportAddress transportAddress = randomFrom(internalCluster().getInstance(HttpServerTransport.class) .boundAddress().boundAddresses()); - assertThat(transportAddress, is(instanceOf(InetSocketTransportAddress.class))); - InetSocketTransportAddress inetSocketTransportAddress = (InetSocketTransportAddress) transportAddress; - return String.format(Locale.ROOT, "https://localhost:%s/", inetSocketTransportAddress.address().getPort()); + return String.format(Locale.ROOT, "https://localhost:%s/", transportAddress.address().getPort()); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiOptionalClientAuthTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiOptionalClientAuthTests.java index 9f6eccc843b..b975d4af696 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiOptionalClientAuthTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiOptionalClientAuthTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.client.RestClient; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecuritySettingsSource; import org.elasticsearch.transport.Transport; @@ -95,8 +95,7 @@ public class PkiOptionalClientAuthTests extends SecurityIntegTestCase { public void testTransportClientWithoutClientCertificate() { Transport transport = internalCluster().getDataNodeInstance(Transport.class); - int port = ((InetSocketTransportAddress) - randomFrom(transport.profileBoundAddresses().get("want_client_auth").boundAddresses())).address().getPort(); + int port = randomFrom(transport.profileBoundAddresses().get("want_client_auth").boundAddresses()).address().getPort(); Settings sslSettingsForStore = getSSLSettingsForStore ("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/truststore-testnode-only.jks", "truststore-testnode-only"); @@ -109,7 +108,7 @@ public class PkiOptionalClientAuthTests extends SecurityIntegTestCase { try (TransportClient client = new TestXPackTransportClient(settings)) { - client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), port)); + client.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), port)); assertGreenClusterState(client); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterIntegrationTests.java index 393d08023c4..7ea939d37f4 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterIntegrationTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.security.transport; import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.discovery.MasterNotDiscoveredException; @@ -87,9 +86,7 @@ public class ServerTransportFilterIntegrationTests extends SecurityIntegTestCase Transport transport = internalCluster().getDataNodeInstance(Transport.class); TransportAddress transportAddress = transport.boundAddress().publishAddress(); - assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class)); - InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address(); - String unicastHost = NetworkAddress.format(inetSocketAddress); + String unicastHost = NetworkAddress.format(transportAddress.address()); // test that starting up a node works Settings nodeSettings = Settings.builder() @@ -118,13 +115,6 @@ public class ServerTransportFilterIntegrationTests extends SecurityIntegTestCase writeFile(xpackConf, "users", configUsers()); writeFile(xpackConf, "users_roles", configUsersRoles()); writeFile(xpackConf, "roles.yml", configRoles()); - - Transport transport = internalCluster().getDataNodeInstance(Transport.class); - TransportAddress transportAddress = transport.profileBoundAddresses().get("client").publishAddress(); - assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class)); - InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address(); - int port = inetSocketAddress.getPort(); - // test that starting up a node works Settings nodeSettings = Settings.builder() .put("xpack.security.authc.realms.file.type", FileRealm.TYPE) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/TransportFilterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/TransportFilterTests.java index d73a0aaffca..90c593f83e7 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/TransportFilterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/TransportFilterTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; @@ -58,7 +59,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @ClusterScope(scope = SUITE, numDataNodes = 0) -@ESIntegTestCase.SuppressLocalMode public class TransportFilterTests extends ESIntegTestCase { @Override @@ -305,7 +305,7 @@ public class TransportFilterTests extends ESIntegTestCase { } @Override - public List getTransportInterceptors() { + public List getTransportInterceptors(NamedWriteableRegistry namedWriteableRegistry) { return Collections.singletonList(new TransportInterceptor() { @Override public TransportRequestHandler interceptHandler(String action, diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/filter/IPFilterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/filter/IPFilterTests.java index 19ba97e619b..6e33674a068 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/filter/IPFilterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/filter/IPFilterTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.BoundTransportAddress; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.license.XPackLicenseState; @@ -68,17 +67,17 @@ public class IPFilterTests extends ESTestCase { TransportSettings.TRANSPORT_PROFILES_SETTING))); httpTransport = mock(HttpServerTransport.class); - InetSocketTransportAddress httpAddress = new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 9200); + TransportAddress httpAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 9200); when(httpTransport.boundAddress()).thenReturn(new BoundTransportAddress(new TransportAddress[] { httpAddress }, httpAddress)); when(httpTransport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); transport = mock(Transport.class); - InetSocketTransportAddress address = new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 9300); + TransportAddress address = new TransportAddress(InetAddress.getLoopbackAddress(), 9300); when(transport.boundAddress()).thenReturn(new BoundTransportAddress(new TransportAddress[]{ address }, address)); when(transport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); Map profileBoundAddresses = Collections.singletonMap("client", - new BoundTransportAddress(new TransportAddress[]{ new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 9500) }, + new BoundTransportAddress(new TransportAddress[]{ new TransportAddress(InetAddress.getLoopbackAddress(), 9500) }, address)); when(transport.profileBoundAddresses()).thenReturn(profileBoundAddresses); } @@ -196,7 +195,7 @@ public class IPFilterTests extends ESTestCase { public void testThatBoundAddressIsNeverRejected() throws Exception { List addressStrings = new ArrayList<>(); for (TransportAddress address : transport.boundAddress().boundAddresses()) { - addressStrings.add(NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress())); + addressStrings.add(NetworkAddress.format(address.address().getAddress())); } Settings settings; diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/filter/IpFilteringIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/filter/IpFilteringIntegrationTests.java index 12ba2e646c9..95f3a980d91 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/filter/IpFilteringIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/filter/IpFilteringIntegrationTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.security.transport.filter; import org.elasticsearch.client.Client; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; @@ -53,11 +52,8 @@ public class IpFilteringIntegrationTests extends SecurityIntegTestCase { public void testThatIpFilteringIsIntegratedIntoNettyPipelineViaHttp() throws Exception { TransportAddress transportAddress = randomFrom(internalCluster().getDataNodeInstance(HttpServerTransport.class).boundAddress().boundAddresses()); - assertThat(transportAddress, is(instanceOf(InetSocketTransportAddress.class))); - InetSocketTransportAddress inetSocketTransportAddress = (InetSocketTransportAddress) transportAddress; - try (Socket socket = new Socket()){ - trySocketConnection(socket, inetSocketTransportAddress.address()); + trySocketConnection(socket, transportAddress.address()); assertThat(socket.isClosed(), is(true)); } } @@ -88,7 +84,6 @@ public class IpFilteringIntegrationTests extends SecurityIntegTestCase { private static int getProfilePort(String profile) { TransportAddress transportAddress = randomFrom(internalCluster().getInstance(Transport.class).profileBoundAddresses().get(profile).boundAddresses()); - assert transportAddress instanceof InetSocketTransportAddress; - return ((InetSocketTransportAddress)transportAddress).address().getPort(); + return transportAddress.address().getPort(); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty3/IPFilterNetty3UpstreamHandlerTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty3/IPFilterNetty3UpstreamHandlerTests.java index 4f78a171f37..8439f4ef613 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty3/IPFilterNetty3UpstreamHandlerTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty3/IPFilterNetty3UpstreamHandlerTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.network.InetAddresses; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.BoundTransportAddress; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.license.XPackLicenseState; @@ -55,7 +54,7 @@ public class IPFilterNetty3UpstreamHandlerTests extends ESTestCase { boolean isHttpEnabled = randomBoolean(); Transport transport = mock(Transport.class); - InetSocketTransportAddress address = new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 9300); + TransportAddress address = new TransportAddress(InetAddress.getLoopbackAddress(), 9300); when(transport.boundAddress()).thenReturn(new BoundTransportAddress(new TransportAddress[] { address }, address)); when(transport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList( @@ -73,7 +72,7 @@ public class IPFilterNetty3UpstreamHandlerTests extends ESTestCase { ipFilter.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses()); if (isHttpEnabled) { HttpServerTransport httpTransport = mock(HttpServerTransport.class); - InetSocketTransportAddress httpAddress = new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 9200); + TransportAddress httpAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 9200); when(httpTransport.boundAddress()).thenReturn(new BoundTransportAddress(new TransportAddress[] { httpAddress }, httpAddress)); when(httpTransport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); ipFilter.setBoundHttpTransportAddress(httpTransport.boundAddress()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty3/SslHostnameVerificationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty3/SslHostnameVerificationTests.java index e4dcddb6521..352b2a6e66c 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty3/SslHostnameVerificationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty3/SslHostnameVerificationTests.java @@ -9,11 +9,9 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.transport.Transport; -import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.TestXPackTransportClient; import java.net.InetSocketAddress; @@ -92,15 +90,14 @@ public class SslHostnameVerificationTests extends SecurityIntegTestCase { public void testThatHostnameMismatchDeniesTransportClientConnection() throws Exception { Transport transport = internalCluster().getDataNodeInstance(Transport.class); TransportAddress transportAddress = transport.boundAddress().publishAddress(); - assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class)); - InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address(); + InetSocketAddress inetSocketAddress = transportAddress.address(); Settings settings = Settings.builder().put(transportClientSettings()) .put("xpack.ssl.verification_mode", "full") .build(); try (TransportClient client = new TestXPackTransportClient(settings)) { - client.addTransportAddress(new InetSocketTransportAddress(inetSocketAddress.getAddress(), inetSocketAddress.getPort())); + client.addTransportAddress(new TransportAddress(inetSocketAddress.getAddress(), inetSocketAddress.getPort())); client.admin().cluster().prepareHealth().get(); fail("Expected a NoNodeAvailableException due to hostname verification failures"); } catch (NoNodeAvailableException e) { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IpFilterRemoteAddressFilterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IpFilterRemoteAddressFilterTests.java index 5d4c59ff662..271195a0be2 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IpFilterRemoteAddressFilterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IpFilterRemoteAddressFilterTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.network.InetAddresses; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.BoundTransportAddress; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.license.XPackLicenseState; @@ -45,7 +44,7 @@ public class IpFilterRemoteAddressFilterTests extends ESTestCase { boolean isHttpEnabled = randomBoolean(); Transport transport = mock(Transport.class); - InetSocketTransportAddress address = new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 9300); + TransportAddress address = new TransportAddress(InetAddress.getLoopbackAddress(), 9300); when(transport.boundAddress()).thenReturn(new BoundTransportAddress(new TransportAddress[] { address }, address)); when(transport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList( @@ -63,7 +62,7 @@ public class IpFilterRemoteAddressFilterTests extends ESTestCase { ipFilter.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses()); if (isHttpEnabled) { HttpServerTransport httpTransport = mock(HttpServerTransport.class); - InetSocketTransportAddress httpAddress = new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 9200); + TransportAddress httpAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 9200); when(httpTransport.boundAddress()).thenReturn(new BoundTransportAddress(new TransportAddress[] { httpAddress }, httpAddress)); when(httpTransport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); ipFilter.setBoundHttpTransportAddress(httpTransport.boundAddress()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ssl/SslIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ssl/SslIntegrationTests.java index e58239921f7..1cd2912d1b5 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ssl/SslIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ssl/SslIntegrationTests.java @@ -20,7 +20,6 @@ import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.xpack.ssl.SSLService; @@ -132,8 +131,7 @@ public class SslIntegrationTests extends SecurityIntegTestCase { private String getNodeUrl() { TransportAddress transportAddress = randomFrom(internalCluster().getInstance(HttpServerTransport.class).boundAddress().boundAddresses()); - assertThat(transportAddress, is(instanceOf(InetSocketTransportAddress.class))); - InetSocketTransportAddress inetSocketTransportAddress = (InetSocketTransportAddress) transportAddress; + TransportAddress inetSocketTransportAddress = transportAddress; return String.format(Locale.ROOT, "https://%s:%s/", "localhost", inetSocketTransportAddress.address().getPort()); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ssl/SslMultiPortTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ssl/SslMultiPortTests.java index e3d2cd5165f..f1f480c06df 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ssl/SslMultiPortTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/transport/ssl/SslMultiPortTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.security.transport.ssl; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.ssl.SSLClientAuth; @@ -123,7 +122,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { */ public void testThatStandardTransportClientCanConnectToNoClientAuthProfile() throws Exception { try(TransportClient transportClient = createTransportClient(Settings.EMPTY)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_client_auth"))); assertGreenClusterState(transportClient); } @@ -138,7 +137,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { */ public void testThatStandardTransportClientCannotConnectToClientProfile() throws Exception { try (TransportClient transportClient = createTransportClient(Settings.EMPTY)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); transportClient.admin().cluster().prepareHealth().get(); fail("Expected NoNodeAvailableException"); } catch (NoNodeAvailableException e) { @@ -153,7 +152,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { */ public void testThatStandardTransportClientCannotConnectToNoSslProfile() throws Exception { try (TransportClient transportClient = createTransportClient(Settings.EMPTY)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_ssl"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_ssl"))); assertGreenClusterState(transportClient); fail("Expected NoNodeAvailableException"); } catch (NoNodeAvailableException e) { @@ -170,7 +169,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { Settings settings = getSSLSettingsForStore( "/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient-client-profile.jks", "testclient-client-profile"); try (TransportClient transportClient = createTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); assertGreenClusterState(transportClient); } } @@ -185,7 +184,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { Settings settings = getSSLSettingsForStore( "/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient-client-profile.jks", "testclient-client-profile"); try (TransportClient transportClient = createTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_client_auth"))); assertGreenClusterState(transportClient); } @@ -219,7 +218,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { Settings settings = getSSLSettingsForStore( "/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient-client-profile.jks", "testclient-client-profile"); try (TransportClient transportClient = createTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_ssl"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_ssl"))); transportClient.admin().cluster().prepareHealth().get(); fail("Expected NoNodeAvailableException"); } catch (NoNodeAvailableException e) { @@ -237,7 +236,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { .put("cluster.name", internalCluster().getClusterName()) .build(); try (TransportClient transportClient = new TestXPackTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_ssl"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_ssl"))); assertGreenClusterState(transportClient); } } @@ -270,7 +269,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { .put("cluster.name", internalCluster().getClusterName()) .build(); try (TransportClient transportClient = new TestXPackTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); assertGreenClusterState(transportClient); fail("Expected NoNodeAvailableException"); } catch (NoNodeAvailableException e) { @@ -288,7 +287,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { .put("cluster.name", internalCluster().getClusterName()) .build(); try (TransportClient transportClient = new TestXPackTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_client_auth"))); assertGreenClusterState(transportClient); fail("Expected NoNodeAvailableException"); @@ -312,7 +311,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { .put("xpack.ssl.truststore.password", "truststore-testnode-only") .build(); try (TransportClient transportClient = new TestXPackTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_client_auth"))); assertGreenClusterState(transportClient); } @@ -334,7 +333,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { .put("xpack.ssl.truststore.password", "truststore-testnode-only") .build(); try (TransportClient transportClient = new TestXPackTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); assertGreenClusterState(transportClient); fail("Expected NoNodeAvailableException"); } catch (NoNodeAvailableException e) { @@ -381,7 +380,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { .put("xpack.ssl.truststore.password", "truststore-testnode-only") .build(); try (TransportClient transportClient = new TestXPackTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_ssl"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_ssl"))); assertGreenClusterState(transportClient); fail("Expected NoNodeAvailableException"); } catch (NoNodeAvailableException e) { @@ -421,7 +420,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { .put("xpack.ssl.client_authentication", SSLClientAuth.REQUIRED) .build(); try (TransportClient transportClient = new TestXPackTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); assertGreenClusterState(transportClient); fail("Expected NoNodeAvailableException"); } catch (NoNodeAvailableException e) { @@ -441,7 +440,7 @@ public class SslMultiPortTests extends SecurityIntegTestCase { .put("xpack.ssl.client_authentication", SSLClientAuth.REQUIRED) .build(); try (TransportClient transportClient = new TestXPackTransportClient(settings)) { - transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), + transportClient.addTransportAddress(new TransportAddress(InetAddress.getLoopbackAddress(), getProfilePort("no_client_auth"))); assertGreenClusterState(transportClient); fail("Expected NoNodeAvailableException"); @@ -453,7 +452,6 @@ public class SslMultiPortTests extends SecurityIntegTestCase { private static int getProfilePort(String profile) { TransportAddress transportAddress = randomFrom(internalCluster().getInstance(Transport.class).profileBoundAddresses().get(profile).boundAddresses()); - assert transportAddress instanceof InetSocketTransportAddress; - return ((InetSocketTransportAddress)transportAddress).address().getPort(); + return transportAddress.address().getPort(); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ssl/SSLReloadIntegTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ssl/SSLReloadIntegTests.java index cd0ed69859e..b14a0f4ab6e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ssl/SSLReloadIntegTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ssl/SSLReloadIntegTests.java @@ -17,10 +17,9 @@ import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.network.InetAddressHelper; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.env.Environment; -import org.elasticsearch.xpack.security.Security; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecuritySettingsSource; import org.elasticsearch.transport.Transport; @@ -114,7 +113,7 @@ public class SSLReloadIntegTests extends SecurityIntegTestCase { String node = randomFrom(internalCluster().getNodeNames()); SSLService sslService = new SSLService(settings, new Environment(settings)); SSLSocketFactory sslSocketFactory = sslService.sslSocketFactory(settings); - InetSocketTransportAddress address = (InetSocketTransportAddress) internalCluster() + TransportAddress address = internalCluster() .getInstance(Transport.class, node).boundAddress().publishAddress(); try (SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(address.getAddress(), address.getPort())) { assertThat(socket.isConnected(), is(true)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 70601128b78..20348ec4cfa 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -26,7 +26,6 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptSettings; import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockMustacheScriptEngine; @@ -41,7 +40,6 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.TestCluster; import org.elasticsearch.test.store.MockFSIndexStore; -import org.elasticsearch.test.transport.AssertingLocalTransport; import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.xpack.support.clock.Clock; import org.elasticsearch.xpack.watcher.WatcherLifeCycleService; @@ -165,7 +163,6 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase // security has its own transport service plugins.remove(MockTransportService.TestPlugin.class); // security has its own transport - plugins.remove(AssertingLocalTransport.TestPlugin.class); // we have to explicitly add it otherwise we will fail to set the check_index_on_close setting plugins.add(MockFSIndexStore.TestPlugin.class); plugins.add(MockMustacheScriptEngine.TestPlugin.class); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java index 1072915c224..46dd8456719 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java @@ -224,7 +224,7 @@ public class HttpSecretsIntegrationTests extends AbstractWatcherIntegrationTestC value = contentSource.getValue("result.actions.0.webhook.request.auth.username"); assertThat(value, notNullValue()); assertThat(value, instanceOf(String.class)); - assertThat((String) value, is(USERNAME)); // the auth username exists + assertThat(value, is(USERNAME)); // the auth username exists value = contentSource.getValue("result.actions.0.webhook.request.auth.password"); assertThat(value, nullValue()); // but the auth password was filtered out diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/NoMasterNodeTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/NoMasterNodeTests.java index 7870376a1d6..d1b18a3438d 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/NoMasterNodeTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/NoMasterNodeTests.java @@ -18,7 +18,6 @@ import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.discovery.zen.ping.ZenPingService; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; -import org.elasticsearch.test.ESIntegTestCase.SuppressLocalMode; import org.elasticsearch.test.discovery.ClusterDiscoveryConfiguration; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.watcher.WatcherService; @@ -55,7 +54,6 @@ import static org.hamcrest.core.Is.is; @BadApple(bugUrl = "https://github.com/elastic/x-plugins/issues/1007") @TestLogging("org.elasticsearch.discovery:TRACE,org.elasticsearch.watcher:TRACE") @ClusterScope(scope = TEST, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false, numDataNodes = 0) -@SuppressLocalMode public class NoMasterNodeTests extends AbstractWatcherIntegrationTestCase { private ClusterDiscoveryConfiguration.UnicastZen config; diff --git a/qa/security-migrate-tests/src/test/java/org/elasticsearch/xpack/security/MigrateToolTestCase.java b/qa/security-migrate-tests/src/test/java/org/elasticsearch/xpack/security/MigrateToolTestCase.java index b7280aa0482..5eb7bf3e6da 100644 --- a/qa/security-migrate-tests/src/test/java/org/elasticsearch/xpack/security/MigrateToolTestCase.java +++ b/qa/security-migrate-tests/src/test/java/org/elasticsearch/xpack/security/MigrateToolTestCase.java @@ -12,9 +12,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient; import org.junit.After; import org.junit.AfterClass; @@ -42,7 +40,6 @@ import static org.hamcrest.Matchers.notNullValue; * your test. */ @LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") -@ESIntegTestCase.SuppressLocalMode public abstract class MigrateToolTestCase extends LuceneTestCase { /** @@ -105,7 +102,7 @@ public abstract class MigrateToolTestCase extends LuceneTestCase { String ip = stringAddress.substring(0, lastColon); String port = stringAddress.substring(lastColon + 1); try { - transportAddresses[i++] = new InetSocketTransportAddress(InetAddress.getByName(ip), Integer.valueOf(port)); + transportAddresses[i++] = new TransportAddress(InetAddress.getByName(ip), Integer.valueOf(port)); } catch (NumberFormatException e) { throw new IllegalArgumentException("port is not valid, expected number but was [" + port + "]"); } diff --git a/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java b/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java index 4b4f7e04ce1..3a26627bd76 100644 --- a/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java +++ b/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.xpack.security.Security; import org.elasticsearch.test.ESIntegTestCase; @@ -134,7 +134,7 @@ public class SmokeTestMonitoringWithSecurityIT extends ESIntegTestCase { InetSocketAddress[] httpAddresses = new InetSocketAddress[nodes.size()]; for (int i = 0; i < nodes.size(); i++) { - httpAddresses[i] = ((InetSocketTransportAddress) nodes.get(i).getHttp().address().publishAddress()).address(); + httpAddresses[i] = nodes.get(i).getHttp().address().publishAddress().address(); } return httpAddresses; }