Search in sources :

Example 16 with PhysicalAddress

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;
}
Also used : IpAddress(org.jgroups.stack.IpAddress) PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress) Tuple(org.jgroups.util.Tuple)

Example 17 with PhysicalAddress

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;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) PhysicalAddress(org.jgroups.PhysicalAddress) IpAddress(org.jgroups.stack.IpAddress)

Example 18 with PhysicalAddress

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));
    }
}
Also used : PingData(org.jgroups.protocols.PingData) Message(org.jgroups.Message) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress) PingHeader(org.jgroups.protocols.PingHeader)

Aggregations

PhysicalAddress (org.jgroups.PhysicalAddress)18 Address (org.jgroups.Address)11 Event (org.jgroups.Event)10 IpAddress (org.jgroups.stack.IpAddress)7 InetAddress (java.net.InetAddress)4 Message (org.jgroups.Message)4 PingData (org.jgroups.protocols.PingData)3 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 Inet6Address (java.net.Inet6Address)2 InetSocketAddress (java.net.InetSocketAddress)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 LocalAddress (org.jgroups.annotations.LocalAddress)2 PingHeader (org.jgroups.protocols.PingHeader)2 RouterStubManager (org.jgroups.stack.RouterStubManager)2 Tuple (org.jgroups.util.Tuple)2 java.io (java.io)1