Search in sources :

Example 81 with IpAddress

use of org.jgroups.stack.IpAddress in project wildfly by wildfly.

the class AddressSerializerTestCase method test.

private static void test(Tester<Address> tester) throws IOException {
    UUID uuid = UUID.randomUUID();
    InetSocketAddress address = new InetSocketAddress(InetAddress.getLoopbackAddress(), Short.MAX_VALUE);
    IpAddress ipAddress = new IpAddress(address);
    IpAddressUUID ipAddressUUID = new IpAddressUUID(address);
    tester.test(uuid);
    tester.test(ipAddress);
    tester.test(ipAddressUUID);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) UUID(org.jgroups.util.UUID) IpAddressUUID(org.jgroups.stack.IpAddressUUID) IpAddressUUID(org.jgroups.stack.IpAddressUUID)

Example 82 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class DefaultDNSResolverTest method test_parsing_srv_entries.

@Test
public void test_parsing_srv_entries() throws Exception {
    // given
    MockDirContext mockDirContext = MockDirContext.newDefault().addEntry("test", "10 100 8888 9089f34a.jgroups-dns-ping.local.", DNSResolver.DNSRecordType.SRV).addEntry("9089f34a.jgroups-dns-ping.local", "192.168.0.1", DNSResolver.DNSRecordType.A).addEntry("9089f34a.jgroups-dns-ping.local", "192.168.0.2", DNSResolver.DNSRecordType.A);
    DefaultDNSResolver resolver = new DefaultDNSResolver(mockDirContext);
    // when
    List<Address> addresses = resolver.resolveIps("test", DNSResolver.DNSRecordType.SRV);
    // then
    List<Address> expectedResults = Arrays.asList(new IpAddress("192.168.0.1"), new IpAddress("192.168.0.2"));
    Assert.assertEquals(addresses, expectedResults);
}
Also used : Address(org.jgroups.Address) IpAddress(org.jgroups.stack.IpAddress) IpAddress(org.jgroups.stack.IpAddress) Test(org.testng.annotations.Test)

Example 83 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class IpAddressTest method testCopy.

public void testCopy() {
    IpAddress tmp = a.copy();
    assert tmp.equals(a);
    tmp = j.copy();
    assert tmp.equals(j);
}
Also used : IpAddress(org.jgroups.stack.IpAddress)

Example 84 with IpAddress

use of org.jgroups.stack.IpAddress 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 85 with IpAddress

use of org.jgroups.stack.IpAddress in project keycloak by keycloak.

the class TopologyInfo method getRouteName.

/**
 * Get route to be used as the identifier for sticky session. Return null if I am not able to find the appropriate route (or in case of local mode)
 */
public String getRouteName(Cache cache, Object key) {
    if (cache.getCacheConfiguration().clustering().cacheMode().isClustered() && isGeneratedNodeName) {
        logger.warn("Clustered configuration used, but node name is not properly set. Make sure to start server with jboss.node.name property identifying cluster node");
    }
    if (isGeneratedNodeName) {
        return null;
    }
    // Impl based on Wildfly sticky session algorithm for generating routes ( org.wildfly.clustering.web.infinispan.session.InfinispanRouteLocator )
    Address address = getOwnerAddress(cache, key);
    // Local mode
    if (address == null || (address == LocalModeAddress.INSTANCE)) {
        return myNodeName;
    }
    org.jgroups.Address jgroupsAddress = toJGroupsAddress(address);
    String name = NameCache.get(jgroupsAddress);
    // If no logical name exists, create one using physical address
    if (name == null) {
        Transport transport = cache.getCacheManager().getTransport();
        JChannel jgroupsChannel = ((JGroupsTransport) transport).getChannel();
        IpAddress ipAddress = (IpAddress) jgroupsChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS, jgroupsAddress));
        // Physical address might be null if node is no longer a member of the cluster
        InetSocketAddress socketAddress = (ipAddress != null) ? new InetSocketAddress(ipAddress.getIpAddress(), ipAddress.getPort()) : new InetSocketAddress(0);
        name = String.format("%s:%s", socketAddress.getHostString(), socketAddress.getPort());
        logger.debugf("Address not found in NameCache. Fallback to %s", name);
    }
    return name;
}
Also used : JChannel(org.jgroups.JChannel) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) LocalModeAddress(org.infinispan.remoting.transport.LocalModeAddress) Address(org.infinispan.remoting.transport.Address) InetSocketAddress(java.net.InetSocketAddress) Event(org.jgroups.Event) IpAddress(org.jgroups.stack.IpAddress) Transport(org.infinispan.remoting.transport.Transport) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport)

Aggregations

IpAddress (org.jgroups.stack.IpAddress)87 InetSocketAddress (java.net.InetSocketAddress)15 Address (org.jgroups.Address)13 InetAddress (java.net.InetAddress)7 Test (org.testng.annotations.Test)7 Event (org.jgroups.Event)6 PhysicalAddress (org.jgroups.PhysicalAddress)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 IOException (java.io.IOException)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 JChannel (org.jgroups.JChannel)3 ManagedOperation (org.jgroups.annotations.ManagedOperation)3 DefaultSocketFactory (org.jgroups.util.DefaultSocketFactory)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 ServerSocket (java.net.ServerSocket)2