private boolean isMessageToSelf(JoinMessage joinMessage) { Address thisAddress = node.getThisAddress(); return thisAddress == null || thisAddress.equals(joinMessage.getAddress()); } }
private boolean isMessageToSelf(JoinMessage joinMessage) { Address thisAddress = node.getThisAddress(); return thisAddress == null || thisAddress.equals(joinMessage.getAddress()); } }
boolean isTrusted(JoinMessage joinMessage) { if (trustedInterfaces.isEmpty()) { return true; } String host = joinMessage.getAddress().getHost(); if (matchAnyInterface(host, trustedInterfaces)) { return true; } else { if (logger.isFineEnabled()) { logger.fine(format( "JoinMessage from %s is dropped because its sender is not a trusted interface", host)); } return false; } } }
boolean isTrusted(JoinMessage joinMessage) { if (trustedInterfaces.isEmpty()) { return true; } String host = joinMessage.getAddress().getHost(); if (matchAnyInterface(host, trustedInterfaces)) { return true; } else { if (logger.isFineEnabled()) { logger.fine(format( "JoinMessage from %s is dropped because its sender is not a trusted interface", host)); } return false; } } }
/** * Respond to a {@link WhoisMasterOp}. * * @param joinMessage the {@code JoinMessage} from the request. * @param connection the connection to operation caller, to which response will be sent. * @see WhoisMasterOp */ public void answerWhoisMasterQuestion(JoinMessage joinMessage, Connection connection) { if (!ensureValidConfiguration(joinMessage)) { return; } if (clusterService.isJoined()) { if (!checkIfJoinRequestFromAnExistingMember(joinMessage, connection)) { sendMasterAnswer(joinMessage.getAddress()); } } else { if (logger.isFineEnabled()) { logger.fine(format("Received a master question from %s," + " but this node is not master itself or doesn't have a master yet!", joinMessage.getAddress())); } } }
/** * Respond to a {@link WhoisMasterOp}. * * @param joinMessage the {@code JoinMessage} from the request. * @param connection the connection to operation caller, to which response will be sent. * @see WhoisMasterOp */ public void answerWhoisMasterQuestion(JoinMessage joinMessage, Connection connection) { if (!ensureValidConfiguration(joinMessage)) { return; } if (clusterService.getMasterAddress() != null) { if (!checkIfJoinRequestFromAnExistingMember(joinMessage, connection)) { sendMasterAnswer(joinMessage.getAddress()); } } else { if (logger.isFineEnabled()) { logger.fine(format("Received a master question from %s," + " but this node is not master itself or doesn't have a master yet!", joinMessage.getAddress())); } } }
/** * Validate that the configuration received from the remote node in {@code joinMessage} is compatible with the * configuration of this node. * * @param joinMessage the {@link JoinMessage} received from another node. * @return {@code true} if packet version of join message matches this node's packet version and configurations * are found to be compatible, otherwise {@code false}. * @throws Exception in case any exception occurred while checking compatibilty * @see ConfigCheck */ public boolean validateJoinMessage(JoinMessage joinMessage) throws Exception { if (joinMessage.getPacketVersion() != Packet.VERSION) { return false; } try { ConfigCheck newMemberConfigCheck = joinMessage.getConfigCheck(); ConfigCheck clusterConfigCheck = node.createConfigCheck(); return clusterConfigCheck.isCompatible(newMemberConfigCheck); } catch (Exception e) { logger.warning(format("Invalid join request from %s, cause: %s", joinMessage.getAddress(), e.getMessage())); throw e; } }
/** * Validate that the configuration received from the remote node in {@code joinMessage} is compatible with the * configuration of this node. * * @param joinMessage the {@link JoinMessage} received from another node. * @return {@code true} if packet version of join message matches this node's packet version and configurations * are found to be compatible, otherwise {@code false}. * @throws Exception in case any exception occurred while checking compatibilty * @see ConfigCheck */ public boolean validateJoinMessage(JoinMessage joinMessage) throws Exception { if (joinMessage.getPacketVersion() != Packet.VERSION) { return false; } try { ConfigCheck newMemberConfigCheck = joinMessage.getConfigCheck(); ConfigCheck clusterConfigCheck = node.createConfigCheck(); return clusterConfigCheck.isCompatible(newMemberConfigCheck); } catch (Exception e) { logger.warning(format("Invalid join request from %s, cause: %s", joinMessage.getAddress(), e.getMessage())); throw e; } }
private boolean checkIfUsingAnExistingMemberUuid(JoinMessage joinMessage) { Member member = clusterService.getMember(joinMessage.getUuid()); Address target = joinMessage.getAddress(); if (member != null && !member.getAddress().equals(joinMessage.getAddress())) { if (clusterService.isMaster() && !isMastershipClaimInProgress()) { String message = "There's already an existing member " + member + " with the same UUID. " + target + " is not allowed to join."; logger.warning(message); } else { sendMasterAnswer(target); } return true; } return false; }
private boolean checkIfUsingAnExistingMemberUuid(JoinMessage joinMessage) { Member member = clusterService.getMember(joinMessage.getUuid()); Address target = joinMessage.getAddress(); if (member != null && !member.getAddress().equals(joinMessage.getAddress())) { if (clusterService.isMaster() && !isMastershipClaimInProgress()) { String message = "There's already an existing member " + member + " with the same UUID. " + target + " is not allowed to join."; logger.warning(message); OperationService operationService = nodeEngine.getOperationService(); operationService.send(new BeforeJoinCheckFailureOp(message), target); } else { sendMasterAnswer(target); } return true; } return false; }
private boolean ensureValidConfiguration(JoinMessage joinMessage) { Address address = joinMessage.getAddress(); try { if (isValidJoinMessage(joinMessage)) { return true; } logger.warning(format("Received an invalid join request from %s, cause: clusters part of different cluster-groups", address)); nodeEngine.getOperationService().send(new GroupMismatchOp(), address); } catch (ConfigMismatchException e) { logger.warning(format("Received an invalid join request from %s, cause: %s", address, e.getMessage())); OperationService operationService = nodeEngine.getOperationService(); operationService.send(new ConfigMismatchOp(e.getMessage()), address); } return false; }
private boolean ensureValidConfiguration(JoinMessage joinMessage) { Address address = joinMessage.getAddress(); try { if (isValidJoinMessage(joinMessage)) { return true; } logger.warning(format("Received an invalid join request from %s, cause: clusters part of different cluster-groups", address)); nodeEngine.getOperationService().send(new GroupMismatchOp(), address); } catch (ConfigMismatchException e) { logger.warning(format("Received an invalid join request from %s, cause: %s", address, e.getMessage())); OperationService operationService = nodeEngine.getOperationService(); operationService.send(new ConfigMismatchOp(e.getMessage()), address); } return false; }
private void handleNotActiveOrNotJoined(JoinMessage joinMessage) { if (isJoinRequest(joinMessage)) { Joiner joiner = node.getJoiner(); if (joiner instanceof MulticastJoiner) { MulticastJoiner multicastJoiner = (MulticastJoiner) joiner; multicastJoiner.onReceivedJoinRequest((JoinRequest) joinMessage); } else { logDroppedMessage(joinMessage); } } else { Address address = joinMessage.getAddress(); if (node.getJoiner().isBlacklisted(address)) { logDroppedMessage(joinMessage); return; } ClusterServiceImpl clusterService = node.getClusterService(); if (!clusterService.isJoined() && clusterService.getMasterAddress() == null) { clusterService.setMasterAddressToJoin(joinMessage.getAddress()); } else { logDroppedMessage(joinMessage); } } }
private void handleNotActiveOrNotJoined(JoinMessage joinMessage) { if (isJoinRequest(joinMessage)) { Joiner joiner = node.getJoiner(); if (joiner instanceof MulticastJoiner) { MulticastJoiner multicastJoiner = (MulticastJoiner) joiner; multicastJoiner.onReceivedJoinRequest((JoinRequest) joinMessage); } else { logDroppedMessage(joinMessage); } } else { Address address = joinMessage.getAddress(); if (node.getJoiner().isBlacklisted(address)) { logDroppedMessage(joinMessage); return; } ClusterServiceImpl clusterService = node.getClusterService(); if (!clusterService.isJoined() && clusterService.getMasterAddress() == null) { clusterService.setMasterAddressToJoin(joinMessage.getAddress()); } else { logDroppedMessage(joinMessage); } } }
private void handleActiveAndJoined(JoinMessage joinMessage) { if (!(joinMessage instanceof JoinRequest)) { logDroppedMessage(joinMessage); return; } ClusterServiceImpl clusterService = node.getClusterService(); Address masterAddress = clusterService.getMasterAddress(); if (clusterService.isMaster()) { JoinMessage response = new JoinMessage(Packet.VERSION, node.getBuildInfo().getBuildNumber(), node.getVersion(), node.getThisAddress(), node.getThisUuid(), node.isLiteMember(), node.createConfigCheck()); node.multicastService.send(response); } else if (joinMessage.getAddress().equals(masterAddress)) { MemberImpl master = node.getClusterService().getMember(masterAddress); if (master != null && !master.getUuid().equals(joinMessage.getUuid())) { String message = "New join request has been received from current master. Suspecting " + masterAddress; logger.warning(message); // I just make a local suspicion. Probably other nodes will eventually suspect as well. clusterService.suspectMember(master, message, false); } } }
private void handleActiveAndJoined(JoinMessage joinMessage) { if (!(joinMessage instanceof JoinRequest)) { logDroppedMessage(joinMessage); return; } ClusterServiceImpl clusterService = node.getClusterService(); Address masterAddress = clusterService.getMasterAddress(); if (clusterService.isMaster()) { JoinMessage response = new JoinMessage(Packet.VERSION, node.getBuildInfo().getBuildNumber(), node.getVersion(), node.getThisAddress(), node.getThisUuid(), node.isLiteMember(), node.createConfigCheck()); node.multicastService.send(response); } else if (joinMessage.getAddress().equals(masterAddress)) { MemberImpl master = node.getClusterService().getMember(masterAddress); if (master != null && !master.getUuid().equals(joinMessage.getUuid())) { String message = "New join request has been received from current master. Suspecting " + masterAddress; logger.warning(message); // I just make a local suspicion. Probably other nodes will eventually suspect as well. clusterService.suspectMember(master, message, false); } } }
private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, Connection connection) { Address target = joinMessage.getAddress(); MemberImpl member = clusterService.getMember(target); if (member == null) {
private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, Connection connection) { Address target = joinMessage.getAddress(); MemberImpl member = clusterService.getMember(target); if (member == null) {