use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class JGroupsMessenger method establishLocalAddress.
private void establishLocalAddress() {
UUID logicalAddress = (UUID) myChannel.getAddress();
logicalAddress = logicalAddress.copy();
IpAddress ipaddr = (IpAddress) myChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS));
if (ipaddr != null) {
this.jgAddress = new JGAddress(logicalAddress, ipaddr);
} else {
UDP udp = (UDP) myChannel.getProtocolStack().getTransport();
try {
Method getAddress = UDP.class.getDeclaredMethod("getPhysicalAddress");
getAddress.setAccessible(true);
ipaddr = (IpAddress) getAddress.invoke(udp, new Object[0]);
this.jgAddress = new JGAddress(logicalAddress, ipaddr);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
logger.info("Unable to find getPhysicallAddress method in UDP - parsing its address instead");
}
// if (this.jgAddress == null) {
// String addr = udp.getLocalPhysicalAddress();
// int cidx = addr.lastIndexOf(':'); // IPv6 literals might have colons
// String host = addr.substring(0, cidx);
// int jgport = Integer.parseInt(addr.substring(cidx+1, addr.length()));
// try {
// this.jgAddress = new JGAddress(logicalAddress, new IpAddress(InetAddress.getByName(host),
// jgport));
// } catch (UnknownHostException e) {
// myChannel.disconnect();
// throw new SystemConnectException("unable to initialize jgroups address", e);
// }
// }
}
// install the address in the JGroups channel protocols
myChannel.down(new Event(Event.SET_LOCAL_ADDRESS, this.jgAddress));
DistributionConfig config = services.getConfig().getDistributionConfig();
boolean isLocator = (services.getConfig().getTransport().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty();
// establish the DistributedSystem's address
DurableClientAttributes dca = null;
if (config.getDurableClientId() != null) {
dca = new DurableClientAttributes(config.getDurableClientId(), config.getDurableClientTimeout());
}
MemberAttributes attr = new MemberAttributes(-1, /* dcPort - not known at this time */
OSProcess.getId(), services.getConfig().getTransport().getVmKind(), -1, /* view id - not known at this time */
config.getName(), MemberAttributes.parseGroups(config.getRoles(), config.getGroups()), dca);
localAddress = new InternalDistributedMember(jgAddress.getInetAddress(), jgAddress.getPort(), config.getEnableNetworkPartitionDetection(), isLocator, attr);
// add the JGroups logical address to the GMSMember
UUID uuid = this.jgAddress;
GMSMember gmsMember = (GMSMember) localAddress.getNetMember();
gmsMember.setUUID(uuid);
gmsMember.setMemberWeight((byte) (services.getConfig().getMemberWeight() & 0xff));
gmsMember.setNetworkPartitionDetectionEnabled(services.getConfig().getDistributionConfig().getEnableNetworkPartitionDetection());
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class GMSJoinLeaveJUnitTest method testQuorumLossNotificationWithNetworkPartitionDetectionDisabled.
@Test
public void testQuorumLossNotificationWithNetworkPartitionDetectionDisabled() throws IOException {
initMocks(false);
prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
// set up a view with sufficient members, then create a new view
// where enough weight is lost to cause a network partition
List<InternalDistributedMember> mbrs = new LinkedList<>();
Set<InternalDistributedMember> shutdowns = new HashSet<>();
Set<InternalDistributedMember> crashes = new HashSet<>();
mbrs.add(mockMembers[0]);
mbrs.add(mockMembers[1]);
mbrs.add(mockMembers[2]);
mbrs.add(gmsJoinLeaveMemberId);
((GMSMember) mockMembers[1].getNetMember()).setMemberWeight((byte) 20);
NetView newView = new NetView(mockMembers[0], gmsJoinLeave.getView().getViewId() + 1, mbrs, shutdowns, crashes);
InstallViewMessage installViewMessage = getInstallViewMessage(newView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
crashes = new HashSet<>(crashes);
crashes.add(mockMembers[1]);
crashes.add(mockMembers[2]);
mbrs = new LinkedList<>(mbrs);
mbrs.remove(mockMembers[1]);
mbrs.remove(mockMembers[2]);
NetView partitionView = new NetView(mockMembers[0], newView.getViewId() + 1, mbrs, shutdowns, crashes);
installViewMessage = getInstallViewMessage(partitionView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
verify(manager, never()).forceDisconnect(isA(String.class));
verify(manager).quorumLost(crashes, newView);
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class GMSHealthMonitorJUnitTest method testClientSocketHandlerWhenLsbDoNotMatch.
@Test
public void testClientSocketHandlerWhenLsbDoNotMatch() throws Exception {
int viewId = 2;
long msb = 3;
long lsb = 4;
GMSMember otherMember = createGMSMember(Version.CURRENT_ORDINAL, viewId, msb, lsb + 1);
GMSMember gmsMember = createGMSMember(Version.CURRENT_ORDINAL, viewId, msb, lsb);
executeTestClientSocketHandler(gmsMember, otherMember, GMSHealthMonitor.ERROR);
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class GMSHealthMonitorJUnitTest method createInternalDistributedMember.
private InternalDistributedMember createInternalDistributedMember(short version, int viewId, long msb, long lsb) throws UnknownHostException {
GMSMember gmsMember = createGMSMember(version, viewId, msb, lsb);
InternalDistributedMember idm = new InternalDistributedMember("localhost", 9000, Version.CURRENT, gmsMember);
// We set to our expected test viewId in the IDM as well as reseting the gms member
idm.setVmViewId(viewId);
gmsMember.setBirthViewId(viewId);
return idm;
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class GMSMembershipManagerJUnitTest method initMocks.
@Before
public void initMocks() throws Exception {
Properties nonDefault = new Properties();
nonDefault.put(ACK_WAIT_THRESHOLD, "1");
nonDefault.put(ACK_SEVERE_ALERT_THRESHOLD, "10");
nonDefault.put(DISABLE_TCP, "true");
nonDefault.put(MCAST_PORT, "0");
nonDefault.put(MCAST_TTL, "0");
nonDefault.put(LOG_FILE, "");
nonDefault.put(LOG_LEVEL, "fine");
nonDefault.put(MEMBER_TIMEOUT, "2000");
nonDefault.put(LOCATORS, "localhost[10344]");
distConfig = new DistributionConfigImpl(nonDefault);
distProperties = nonDefault;
RemoteTransportConfig tconfig = new RemoteTransportConfig(distConfig, DistributionManager.NORMAL_DM_TYPE);
mockConfig = mock(ServiceConfig.class);
when(mockConfig.getDistributionConfig()).thenReturn(distConfig);
when(mockConfig.getTransport()).thenReturn(tconfig);
authenticator = mock(Authenticator.class);
myMemberId = new InternalDistributedMember("localhost", 8887);
messenger = mock(Messenger.class);
when(messenger.getMemberID()).thenReturn(myMemberId);
stopper = mock(Stopper.class);
when(stopper.isCancelInProgress()).thenReturn(false);
healthMonitor = mock(HealthMonitor.class);
when(healthMonitor.getFailureDetectionPort()).thenReturn(Integer.valueOf(-1));
joinLeave = mock(JoinLeave.class);
services = mock(Services.class);
when(services.getAuthenticator()).thenReturn(authenticator);
when(services.getConfig()).thenReturn(mockConfig);
when(services.getMessenger()).thenReturn(messenger);
when(services.getCancelCriterion()).thenReturn(stopper);
when(services.getHealthMonitor()).thenReturn(healthMonitor);
when(services.getJoinLeave()).thenReturn(joinLeave);
Timer t = new Timer(true);
when(services.getTimer()).thenReturn(t);
Random r = new Random();
mockMembers = new InternalDistributedMember[5];
for (int i = 0; i < mockMembers.length; i++) {
mockMembers[i] = new InternalDistributedMember("localhost", 8888 + i);
GMSMember m = (GMSMember) mockMembers[i].getNetMember();
UUID uuid = new UUID(r.nextLong(), r.nextLong());
m.setUUID(uuid);
}
members = new ArrayList<>(Arrays.asList(mockMembers));
listener = mock(DistributedMembershipListener.class);
manager = new GMSMembershipManager(listener);
manager.init(services);
when(services.getManager()).thenReturn(manager);
}
Aggregations