use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.
the class DiscoveryNodeTests method testDiscoveryNodeIsCreatedWithHostFromInetAddress.
public void testDiscoveryNodeIsCreatedWithHostFromInetAddress() throws Exception {
InetAddress inetAddress = randomBoolean() ? InetAddress.getByName("192.0.2.1") : InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1 });
TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535));
DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(), emptySet(), Version.CURRENT);
assertEquals(transportAddress.address().getHostString(), node.getHostName());
assertEquals(transportAddress.getAddress(), node.getHostAddress());
}
use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.
the class RoutingNodeTests method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
InetAddress inetAddress = InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1 });
TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535));
DiscoveryNode discoveryNode = new DiscoveryNode("name1", "node-1", transportAddress, emptyMap(), emptySet(), Version.CURRENT);
routingNode = new RoutingNode("node1", discoveryNode, unassignedShard0, initializingShard0, relocatingShard0);
}
use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.
the class DiscoveryNodesTests method testDeltas.
public void testDeltas() {
Set<DiscoveryNode> nodesA = new HashSet<>();
nodesA.addAll(randomNodes(1 + randomInt(10)));
Set<DiscoveryNode> nodesB = new HashSet<>();
nodesB.addAll(randomNodes(1 + randomInt(5)));
for (DiscoveryNode node : randomSubsetOf(nodesA)) {
if (randomBoolean()) {
// change an attribute
Map<String, String> attrs = new HashMap<>(node.getAttributes());
attrs.put("new", "new");
final TransportAddress nodeAddress = node.getAddress();
node = new DiscoveryNode(node.getName(), node.getId(), node.getEphemeralId(), nodeAddress.address().getHostString(), nodeAddress.getAddress(), nodeAddress, attrs, node.getRoles(), node.getVersion());
}
nodesB.add(node);
}
DiscoveryNode masterA = randomBoolean() ? null : RandomPicks.randomFrom(random(), nodesA);
DiscoveryNode masterB = randomBoolean() ? null : RandomPicks.randomFrom(random(), nodesB);
DiscoveryNodes.Builder builderA = DiscoveryNodes.builder();
nodesA.stream().forEach(builderA::add);
final String masterAId = masterA == null ? null : masterA.getId();
builderA.masterNodeId(masterAId);
builderA.localNodeId(RandomPicks.randomFrom(random(), nodesA).getId());
DiscoveryNodes.Builder builderB = DiscoveryNodes.builder();
nodesB.stream().forEach(builderB::add);
final String masterBId = masterB == null ? null : masterB.getId();
builderB.masterNodeId(masterBId);
builderB.localNodeId(RandomPicks.randomFrom(random(), nodesB).getId());
final DiscoveryNodes discoNodesA = builderA.build();
final DiscoveryNodes discoNodesB = builderB.build();
logger.info("nodes A: {}", discoNodesA);
logger.info("nodes B: {}", discoNodesB);
DiscoveryNodes.Delta delta = discoNodesB.delta(discoNodesA);
if (masterA == null) {
assertThat(delta.previousMasterNode(), nullValue());
} else {
assertThat(delta.previousMasterNode().getId(), equalTo(masterAId));
}
if (masterB == null) {
assertThat(delta.newMasterNode(), nullValue());
} else {
assertThat(delta.newMasterNode().getId(), equalTo(masterBId));
}
if (Objects.equals(masterAId, masterBId)) {
assertFalse(delta.masterNodeChanged());
} else {
assertTrue(delta.masterNodeChanged());
}
Set<DiscoveryNode> newNodes = new HashSet<>(nodesB);
newNodes.removeAll(nodesA);
assertThat(delta.added(), equalTo(newNodes.isEmpty() == false));
assertThat(delta.addedNodes(), containsInAnyOrder(newNodes.stream().collect(Collectors.toList()).toArray()));
assertThat(delta.addedNodes().size(), equalTo(newNodes.size()));
Set<DiscoveryNode> removedNodes = new HashSet<>(nodesA);
removedNodes.removeAll(nodesB);
assertThat(delta.removed(), equalTo(removedNodes.isEmpty() == false));
assertThat(delta.removedNodes(), containsInAnyOrder(removedNodes.stream().collect(Collectors.toList()).toArray()));
assertThat(delta.removedNodes().size(), equalTo(removedNodes.size()));
}
use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.
the class HttpInfo method toXContent.
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.HTTP);
builder.array(Fields.BOUND_ADDRESS, (Object[]) address.boundAddresses());
TransportAddress publishAddress = address.publishAddress();
String publishAddressString = publishAddress.toString();
String hostString = publishAddress.address().getHostString();
if (CNAME_IN_PUBLISH_HOST) {
deprecationLogger.deprecate("cname_in_publish_address", "opensearch.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " + "formatting. Remove this property to get rid of this deprecation warning.");
}
if (InetAddresses.isInetAddress(hostString) == false) {
publishAddressString = hostString + '/' + publishAddress.toString();
}
builder.field(Fields.PUBLISH_ADDRESS, publishAddressString);
builder.humanReadableField(Fields.MAX_CONTENT_LENGTH_IN_BYTES, Fields.MAX_CONTENT_LENGTH, maxContentLength());
builder.endObject();
return builder;
}
use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.
the class BootstrapChecksTests method testEnforceLimitsWhenPublishingToNonLocalAddress.
public void testEnforceLimitsWhenPublishingToNonLocalAddress() {
final List<TransportAddress> transportAddresses = new ArrayList<>();
for (int i = 0; i < randomIntBetween(1, 8); i++) {
final TransportAddress randomTransportAddress = buildNewFakeTransportAddress();
transportAddresses.add(randomTransportAddress);
}
final TransportAddress publishAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 0);
final BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);
final String discoveryType = randomFrom(ZEN2_DISCOVERY_TYPE, "single-node");
assertEquals(BootstrapChecks.enforceLimits(boundTransportAddress, discoveryType), !"single-node".equals(discoveryType));
}
Aggregations