use of org.jgroups.PhysicalAddress in project fabric8 by fabric8io.
the class KubernetesDiscovery method down.
public Object down(Event evt) {
Object retval = super.down(evt);
switch(evt.getType()) {
case Event.VIEW_CHANGE:
for (Address logical_addr : members) {
PhysicalAddress physical_addr = (PhysicalAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, logical_addr));
if (physical_addr != null && !kubernetesHosts.contains(physical_addr)) {
dynamic_hosts.addIfAbsent(physical_addr);
}
}
break;
case Event.SET_PHYSICAL_ADDRESS:
Tuple<Address, PhysicalAddress> tuple = (Tuple<Address, PhysicalAddress>) evt.getArg();
PhysicalAddress physical_addr = tuple.getVal2();
if (physical_addr != null && !kubernetesHosts.contains(physical_addr))
dynamic_hosts.addIfAbsent(physical_addr);
break;
}
return retval;
}
use of org.jgroups.PhysicalAddress in project fabric8 by fabric8io.
the class KubernetesDiscovery method findKubernetesHosts.
public List<PhysicalAddress> findKubernetesHosts() {
List<PhysicalAddress> addresses = new ArrayList<>();
Map<String, String> labels = Collections.singletonMap(Constants.JGROUPS_CLUSTER_NAME, cluster_name);
for (Pod pod : client.pods().withLabels(labels).list().getItems()) {
List<Container> containers = KubernetesHelper.getContainers(pod);
for (Container container : containers) {
for (ContainerPort port : container.getPorts()) {
if (Constants.JGROUPS_TCP_PORT.equals(port.getName())) {
try {
String ip = pod.getStatus().getPodIP();
if (ip != null) {
addresses.add(new IpAddress(ip, port.getContainerPort()));
}
} catch (Exception ex) {
LOGGER.warn("Failed to create Address {}.", pod.getStatus().getPodIP());
}
}
}
}
}
return addresses;
}
use of org.jgroups.PhysicalAddress in project fabric8 by jboss-fuse.
the class KubernetesDiscovery method findMembers.
@Override
public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) {
kubernetesHosts = findKubernetesHosts();
PhysicalAddress physical_addr = (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
// https://issues.jboss.org/browse/JGRP-1670
PingData data = new PingData(local_addr, false, org.jgroups.util.UUID.get(local_addr), physical_addr);
PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name);
Set<PhysicalAddress> cluster_members = new HashSet<>(kubernetesHosts);
cluster_members.addAll(dynamic_hosts);
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)
for (PhysicalAddress phys_addr : list) if (!cluster_members.contains(phys_addr))
cluster_members.add(phys_addr);
}
for (final PhysicalAddress addr : cluster_members) {
if (// no need to send the request to myself
physical_addr != null && addr.equals(physical_addr))
continue;
// the message needs to be DONT_BUNDLE, see explanation above
final Message msg = new Message(addr).setFlag(Message.Flag.INTERNAL, Message.Flag.DONT_BUNDLE, Message.Flag.OOB).putHeader(this.id, hdr).setBuffer(marshal(data));
log.trace("%s: sending discovery request to %s", local_addr, msg.getDest());
down_prot.down(new Event(Event.MSG, msg));
}
}
Aggregations