use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class GMSJoinLeave method processJoinRequest.
/**
* process a join request from another member. If this is the coordinator this method will enqueue
* the request for processing in another thread. If this is not the coordinator but the
* coordinator is known, the message is forwarded to the coordinator.
*
* @param incomingRequest the request to be processed
*/
private void processJoinRequest(JoinRequestMessage incomingRequest) {
logger.info("received join request from {}", incomingRequest.getMemberID());
if (incomingRequest.getMemberID().getVersionObject().compareTo(Version.CURRENT) < 0) {
logger.warn("detected an attempt to start a peer using an older version of the product {}", incomingRequest.getMemberID());
JoinResponseMessage m = new JoinResponseMessage("Rejecting the attempt of a member using an older version of the " + "product to join the distributed system", incomingRequest.getRequestId());
m.setRecipient(incomingRequest.getMemberID());
services.getMessenger().send(m);
return;
}
Object creds = incomingRequest.getCredentials();
String rejection;
try {
rejection = services.getAuthenticator().authenticate(incomingRequest.getMemberID(), (Properties) creds);
} catch (Exception e) {
rejection = e.getMessage();
}
if (rejection != null && rejection.length() > 0) {
JoinResponseMessage m = new JoinResponseMessage(rejection, 0);
m.setRecipient(incomingRequest.getMemberID());
services.getMessenger().send(m);
return;
}
// Remove JoinResponseMessage to fix GEODE-870
// if (!this.localAddress.getNetMember().preferredForCoordinator() &&
// incomingRequest.getMemberID().getNetMember().preferredForCoordinator()) {
// JoinResponseMessage joinResponseMessage = new
// JoinResponseMessage(incomingRequest.getMemberID(), currentView, true);
// services.getMessenger().send(joinResponseMessage);
// return;
// }
recordViewRequest(incomingRequest);
}
use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class JGroupsMessenger method filterIncomingMessage.
void filterIncomingMessage(DistributionMessage m) {
switch(m.getDSFID()) {
case JOIN_RESPONSE:
JoinResponseMessage jrsp = (JoinResponseMessage) m;
if (jrsp.getRejectionMessage() == null && services.getConfig().getTransport().isMcastEnabled()) {
byte[] serializedDigest = jrsp.getMessengerData();
ByteArrayInputStream bis = new ByteArrayInputStream(serializedDigest);
DataInputStream dis = new DataInputStream(bis);
try {
Digest digest = new Digest();
digest.readFrom(dis);
logger.trace("installing JGroups message digest {}", digest);
this.myChannel.getProtocolStack().getTopProtocol().down(new Event(Event.MERGE_DIGEST, digest));
jrsp.setMessengerData(null);
} catch (Exception e) {
logger.fatal("Unable to read JGroups messaging digest", e);
}
}
break;
default:
break;
}
}
use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class GMSJoinLeave method attemptToJoin.
/**
* send a join request and wait for a reply. Process the reply. This may throw a
* SystemConnectException or an AuthenticationFailedException
*
* @return true if the attempt succeeded, false if it timed out
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "WA_NOT_IN_LOOP")
boolean attemptToJoin() {
SearchState state = searchState;
// send a join request to the coordinator and wait for a response
InternalDistributedMember coord = state.possibleCoordinator;
if (state.alreadyTried.contains(coord)) {
logger.info("Probable coordinator is still {} - waiting for a join-response", coord);
} else {
logger.info("Attempting to join the distributed system through coordinator " + coord + " using address " + this.localAddress);
int port = services.getHealthMonitor().getFailureDetectionPort();
JoinRequestMessage req = new JoinRequestMessage(coord, this.localAddress, services.getAuthenticator().getCredentials(coord), port, services.getMessenger().getRequestId());
// services.getMessenger().send(req, state.view);
services.getMessenger().send(req);
}
JoinResponseMessage response;
try {
response = waitForJoinResponse();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
if (response == null) {
if (!isJoined) {
logger.debug("received no join response");
}
return isJoined;
}
logger.debug("received join response {}", response);
joinResponse[0] = null;
String failReason = response.getRejectionMessage();
if (failReason != null) {
if (failReason.contains("Rejecting the attempt of a member using an older version") || failReason.contains("15806")) {
throw new SystemConnectException(failReason);
} else if (failReason.contains("Failed to find credentials")) {
throw new AuthenticationRequiredException(failReason);
}
throw new GemFireSecurityException(failReason);
}
// there is no way we can rech here right now
throw new RuntimeException("Join Request Failed with response " + joinResponse[0]);
}
use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class GMSJoinLeaveJUnitTest method testCoordinatorFindRequestSuccess.
@Test
public void testCoordinatorFindRequestSuccess() throws Exception {
try {
initMocks(false);
HashSet<InternalDistributedMember> registrants = new HashSet<>();
registrants.add(mockMembers[0]);
FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true, null);
NetView view = createView();
JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view, 0);
TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class);
gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper);
FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new HashSet<>(), -1, null, 0, "");
int connectTimeout = (int) services.getConfig().getMemberTimeout() * 2;
when(tcpClientWrapper.sendCoordinatorFindRequest(new InetSocketAddress("localhost", 12345), fcreq, connectTimeout)).thenReturn(fcr);
callAsnyc(() -> {
gmsJoinLeave.installView(view);
});
assertTrue("Should be able to join ", gmsJoinLeave.join());
} finally {
}
}
use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.
the class JGroupsMessenger method filterOutgoingMessage.
/** look for certain messages that may need to be altered before being sent */
void filterOutgoingMessage(DistributionMessage m) {
switch(m.getDSFID()) {
case JOIN_RESPONSE:
JoinResponseMessage jrsp = (JoinResponseMessage) m;
if (jrsp.getRejectionMessage() == null && services.getConfig().getTransport().isMcastEnabled()) {
// get the multicast message digest and pass it with the join response
Digest digest = (Digest) this.myChannel.getProtocolStack().getTopProtocol().down(Event.GET_DIGEST_EVT);
HeapDataOutputStream hdos = new HeapDataOutputStream(500, Version.CURRENT);
try {
digest.writeTo(hdos);
} catch (Exception e) {
logger.fatal("Unable to serialize JGroups messaging digest", e);
}
jrsp.setMessengerData(hdos.toByteArray());
}
break;
default:
break;
}
}
Aggregations