use of org.jgroups.stack.IpAddress in project openshift-ping by jboss-openshift.
the class OpenshiftPing method sendMcastDiscoveryRequest.
@Override
protected void sendMcastDiscoveryRequest(Message msg) {
final List<InetSocketAddress> hosts = readAll();
final PhysicalAddress physical_addr = (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
if (!(physical_addr instanceof IpAddress)) {
log.error("Unable to send PING requests: physical_addr is not an IpAddress.");
return;
}
// XXX: is it better to force this to be defined?
// assume symmetry
final int port = ((IpAddress) physical_addr).getPort();
for (InetSocketAddress host : hosts) {
// JGroups messages cannot be reused - https://github.com/belaban/workshop/blob/master/slides/admin.adoc#problem-9-reusing-a-message-the-sebastian-problem
Message msgToHost = msg.copy();
msgToHost.dest(new IpAddress(host.getAddress(), port));
sendDown(down_prot, msgToHost);
}
}
use of org.jgroups.stack.IpAddress in project jgroups-kubernetes by jgroups-extras.
the class KUBE_PING method findMembers.
public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) {
List<Pod> hosts = readAll();
List<PhysicalAddress> cluster_members = new ArrayList<>(hosts != null ? hosts.size() : 16);
PhysicalAddress physical_addr = null;
PingData data = null;
physical_addr = getCurrentPhysicalAddress(local_addr);
// https://issues.jboss.org/browse/JGRP-1670
data = new PingData(local_addr, false, NameCache.get(local_addr), physical_addr);
if (members != null && members.size() <= max_members_in_discovery_request)
data.mbrs(members);
if (hosts != null) {
if (log.isTraceEnabled())
log.trace("%s: hosts fetched from Kubernetes: %s", local_addr, hosts);
for (Pod host : hosts) {
if (!host.isReady() && !useNotReadyAddresses)
continue;
for (int i = 0; i <= port_range; i++) {
try {
IpAddress addr = new IpAddress(host.getIp(), tp_bind_port + i);
if (!cluster_members.contains(addr))
cluster_members.add(addr);
} catch (Exception ex) {
log.warn("failed translating host %s into InetAddress: %s", host, ex);
}
}
}
}
if (use_disk_cache) {
// this only makes sense if we have PDC below us
Collection<PhysicalAddress> list = (Collection<PhysicalAddress>) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESSES));
if (list != null)
list.stream().filter(phys_addr -> !cluster_members.contains(phys_addr)).forEach(cluster_members::add);
}
if (split_clusters_during_rolling_update) {
if (physical_addr != null) {
String senderIp = ((IpAddress) physical_addr).getIpAddress().getHostAddress();
// Please note we search for sender parent group through all pods, ever not ready. It's because JGroup discovery is performed
// before WildFly can respond to http readiness probe.
hosts.stream().filter(p -> p.getPodGroup() == null).forEach(p -> log.warn("Pod %s doesn't have group assigned. Impossible to reliably determine pod group during Rolling Update."));
String senderPodGroup = hosts.stream().filter(pod -> senderIp.contains(pod.getIp())).map(Pod::getPodGroup).findFirst().orElse(null);
if (senderPodGroup != null) {
Set<String> allowedAddresses = hosts.stream().filter(pod -> senderPodGroup.equals(pod.getPodGroup())).map(Pod::getIp).collect(Collectors.toSet());
for (Iterator<PhysicalAddress> memberIterator = cluster_members.iterator(); memberIterator.hasNext(); ) {
IpAddress podAddress = (IpAddress) memberIterator.next();
if (!allowedAddresses.contains(podAddress.getIpAddress().getHostAddress())) {
log.trace("removing pod %s from cluster members list since its parent domain is different than senders (%s). Allowed hosts: %s", podAddress, senderPodGroup, allowedAddresses);
memberIterator.remove();
}
}
} else {
log.warn("split_clusters_during_rolling_update is set to 'true' but can't obtain local node parent deployment. All nodes will be placed in the same cluster.");
}
} else {
log.warn("split_clusters_during_rolling_update is set to 'true' but can't obtain local node IP address. All nodes will be placed in the same cluster.");
}
}
if (log.isTraceEnabled())
log.trace("%s: sending discovery requests to %s", local_addr, cluster_members);
PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name).initialDiscovery(initial_discovery);
for (final PhysicalAddress addr : cluster_members) {
if (// no need to send the request to myself
addr.equals(physical_addr))
continue;
// the message needs to be DONT_BUNDLE, see explanation above
final Message msg = new BytesMessage(addr).setFlag(Message.Flag.DONT_BUNDLE, Message.Flag.OOB).putHeader(this.id, hdr);
if (data != null)
msg.setArray(marshal(data));
if (async_discovery_use_separate_thread_per_request)
timer.execute(() -> sendDiscoveryRequest(msg), sends_can_block);
else
sendDiscoveryRequest(msg);
}
}
Aggregations