org.jgroups.stack.IpAddress Java Examples

The following examples show how to use org.jgroups.stack.IpAddress. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RollingUpdateTest.java    From jgroups-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testPuttingAllNodesInTheSameClusterDuringRollingUpdate() throws Exception {
   //given
   KUBE_PING_FOR_TESTING testedProtocol = new KUBE_PING_FOR_TESTING("/openshift_rolling_update.json");

   //when
   sendInitialDiscovery(testedProtocol);
   Set<String> membersUsedForDiscovery = testedProtocol.getCollectedMessages().stream()
         .map(e -> ((IpAddress)e.getDest()).getIpAddress().getHostAddress())
         .collect(Collectors.toSet());
   List<String> allPodsFromKubernetesApi = testedProtocol.getPods().stream()
         .map(Pod::getIp)
         .collect(Collectors.toList());

   //then
   Assertions.assertThat(membersUsedForDiscovery).hasSameElementsAs(allPodsFromKubernetesApi);
}
 
Example #2
Source File: RollingUpdateTest.java    From jgroups-kubernetes with Apache License 2.0 6 votes vote down vote up
private void testPutOnlyNodesWithTheSameParentDuringRollingUpdate(KUBE_PING_FOR_TESTING testedProtocol) throws Exception {
   //when
   sendInitialDiscovery(testedProtocol);
   String senderParentDeployment = testedProtocol.getPods().stream()
         .filter(pod -> "127.0.0.1".equals(pod.getIp()))
         .map(Pod::getPodGroup)
         .findFirst().get();
   Set<String> membersUsedForDiscovery = testedProtocol.getCollectedMessages().stream()
           .map(e -> ((IpAddress)e.getDest()).getIpAddress().getHostAddress())
           .collect(Collectors.toSet());
   List<String> allowedPodsFromKubernetesApi = testedProtocol.getPods().stream()
         .filter(pod -> senderParentDeployment.equals(pod.getPodGroup()))
         .map(Pod::getIp)
         .collect(Collectors.toList());

   //then
   Assertions.assertThat(allowedPodsFromKubernetesApi).containsAll(membersUsedForDiscovery);
}
 
Example #3
Source File: OpenshiftPing.java    From openshift-ping with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: JGroupsReportingLifeCycleListener.java    From jwala with Apache License 2.0 5 votes vote down vote up
private IpAddress getDestAddr() throws Exception {
    if (null != jgroupsCoordinatorIp) {
        return new IpAddress(jgroupsCoordinatorIp + ":" + jgroupsCoordinatorPort);
    } else {
        if (null == this.jgroupsCoordinatorHostname) {
            final String errorMessage = MessageFormat.format("Expecting hostname specified as JGroupsReportingLifecycleListener attribute {0} when no IP address specified for the JGroups coordinator", JGROUPS_COORDINATOR_HOSTNAME);
            LOGGER.error(errorMessage);
            throw new RuntimeException(errorMessage);
        }
        return getIPAddressFromHostname(jgroupsCoordinatorHostname);
    }
}
 
Example #5
Source File: JGroupsStateReporter.java    From jwala with Apache License 2.0 5 votes vote down vote up
public JGroupsStateReporter(final JGroupsMessagingServiceImpl messagingService, final String serverId,
        final String serverName, final IpAddress coordinator, final int schedulerThreadCount,
        final long schedulerDelayInitial, final long schedulerDelaySubsequent, final TimeUnit schedulerDelayUnit) {
    this.messagingService = messagingService;
    this.serverId = serverId;
    this.serverName = serverName;
    this.coordinator = coordinator;
    this.schedulerThreadCount = schedulerThreadCount;
    this.schedulerDelayInitial = schedulerDelayInitial;
    this.schedulerDelaySubsequent = schedulerDelaySubsequent;
    this.schedulerDelayUnit = schedulerDelayUnit;
}
 
Example #6
Source File: JGroupsServerInfoMessageBuilderTest.java    From jwala with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildMsg() throws Exception {
    final Message msg = new JGroupsServerInfoMessageBuilder().setServerId("1")
                                                             .setState(LifecycleState.STOPPED)
                                                             .setSrcAddress(new IpAddress("localhost"))
                                                             .setDestAddress(new IpAddress("localhost"))
                                                             .build();
    assertNotNull(msg);
}
 
Example #7
Source File: TopologyInfo.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}