use of org.apache.geode.internal.admin.remote.DistributionLocatorId in project geode by apache.
the class WanLocatorDiscovererImpl method exchangeLocalLocators.
/**
* For WAN 70 Exchange the locator information within the distributed system
*
* @param config
* @param hostnameForClients
*/
private void exchangeLocalLocators(int port, DistributionConfigImpl config, LocatorMembershipListener locatorListener, final String hostnameForClients) {
String localLocator = config.getStartLocator();
DistributionLocatorId locatorId = null;
if (localLocator.equals(DistributionConfig.DEFAULT_START_LOCATOR)) {
locatorId = new DistributionLocatorId(port, config.getBindAddress(), hostnameForClients);
} else {
locatorId = new DistributionLocatorId(localLocator);
}
LocatorHelper.addLocator(config.getDistributedSystemId(), locatorId, locatorListener, null);
RemoteLocatorJoinRequest request = buildRemoteDSJoinRequest(port, config, hostnameForClients);
StringTokenizer locatorsOnThisVM = new StringTokenizer(config.getLocators(), ",");
while (locatorsOnThisVM.hasMoreTokens()) {
DistributionLocatorId localLocatorId = new DistributionLocatorId(locatorsOnThisVM.nextToken());
if (!locatorId.equals(localLocatorId)) {
LocatorDiscovery localDiscovery = new LocatorDiscovery(this, localLocatorId, request, locatorListener);
LocatorDiscovery.LocalLocatorDiscovery localLocatorDiscovery = localDiscovery.new LocalLocatorDiscovery();
this._executor.execute(localLocatorDiscovery);
}
}
}
use of org.apache.geode.internal.admin.remote.DistributionLocatorId in project geode by apache.
the class LocatorDiscovery method exchangeRemoteLocators.
public void exchangeRemoteLocators() {
int retryAttempt = 1;
DistributionLocatorId remoteLocator = this.locatorId;
while (!getDiscoverer().isStopped()) {
RemoteLocatorJoinResponse response;
try {
response = (RemoteLocatorJoinResponse) locatorClient.requestToServer(remoteLocator.getHost(), remoteLocator.getPort(), request, WanLocatorDiscoverer.WAN_LOCATOR_CONNECTION_TIMEOUT);
if (response != null) {
LocatorHelper.addExchangedLocators(response.getLocators(), this.locatorListener);
logger.info(LocalizedMessage.create(LocalizedStrings.LOCATOR_DISCOVERY_TASK_EXCHANGED_LOCATOR_INFORMATION_0_WITH_1, new Object[] { request.getLocator(), locatorId, response.getLocators() }));
RemoteLocatorPingRequest pingRequest = new RemoteLocatorPingRequest("");
while (true) {
Thread.sleep(WAN_LOCATOR_PING_INTERVAL);
RemoteLocatorPingResponse pingResponse = (RemoteLocatorPingResponse) locatorClient.requestToServer(remoteLocator.getHost(), remoteLocator.getPort(), pingRequest, WanLocatorDiscoverer.WAN_LOCATOR_CONNECTION_TIMEOUT);
if (pingResponse != null) {
continue;
}
break;
}
}
} catch (IOException ioe) {
if (retryAttempt == WAN_LOCATOR_CONNECTION_RETRY_ATTEMPT) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.LOCATOR_DISCOVERY_TASK_COULD_NOT_EXCHANGE_LOCATOR_INFORMATION_0_WITH_1_AFTER_2, new Object[] { request.getLocator(), remoteLocator, retryAttempt }), ioe);
break;
}
if (skipFailureLogging(remoteLocator)) {
logger.warn(LocalizedMessage.create(LocalizedStrings.LOCATOR_DISCOVERY_TASK_COULD_NOT_EXCHANGE_LOCATOR_INFORMATION_0_WITH_1_AFTER_2_RETRYING_IN_3_MS, new Object[] { request.getLocator(), remoteLocator, retryAttempt, WAN_LOCATOR_CONNECTION_INTERVAL }));
}
try {
Thread.sleep(WAN_LOCATOR_CONNECTION_INTERVAL);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
retryAttempt++;
continue;
} catch (ClassNotFoundException classNotFoundException) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.LOCATOR_DISCOVERY_TASK_ENCOUNTERED_UNEXPECTED_EXCEPTION), classNotFoundException);
break;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
use of org.apache.geode.internal.admin.remote.DistributionLocatorId in project geode by apache.
the class ClusterConfigurationLoader method requestConfigurationFromLocators.
/**
* Request the shared configuration for group(s) from locator(s) this member is bootstrapped with.
*
* This will request the group config this server belongs plus the "cluster" config
*
* @param config this member's configuration.
* @return {@link ConfigurationResponse}
*/
public static ConfigurationResponse requestConfigurationFromLocators(DistributionConfig config, List<String> locatorList) throws ClusterConfigurationNotAvailableException, UnknownHostException {
List<String> groups = ClusterConfigurationLoader.getGroups(config);
ConfigurationRequest request = new ConfigurationRequest();
request.addGroups(ClusterConfigurationService.CLUSTER_CONFIG);
for (String group : groups) {
request.addGroups(group);
}
request.setNumAttempts(10);
ConfigurationResponse response = null;
// Try talking to all the locators in the list
// to get the shared configuration.
TcpClient client = new TcpClient();
for (String locatorInfo : locatorList) {
DistributionLocatorId dlId = new DistributionLocatorId(locatorInfo);
String ipaddress = dlId.getBindAddress();
InetAddress locatorInetAddress = null;
if (StringUtils.isNotBlank(ipaddress)) {
locatorInetAddress = InetAddress.getByName(ipaddress);
} else {
locatorInetAddress = dlId.getHost();
}
int port = dlId.getPort();
try {
response = (ConfigurationResponse) client.requestToServer(locatorInetAddress, port, request, 10000);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Log
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
if (response == null || response.failedToGetSharedConfig()) {
throw new ClusterConfigurationNotAvailableException(LocalizedStrings.Launcher_Command_FAILED_TO_GET_SHARED_CONFIGURATION.toLocalizedString());
}
return response;
}
use of org.apache.geode.internal.admin.remote.DistributionLocatorId in project geode by apache.
the class DistributionLocatorImpl method isRunning.
public boolean isRunning() {
DM dm = ((AdminDistributedSystemImpl) getDistributedSystem()).getDistributionManager();
if (dm == null) {
try {
return this.controller.isRunning(this);
} catch (IllegalStateException e) {
return false;
}
}
String host = getConfig().getHost();
int port = getConfig().getPort();
String bindAddress = getConfig().getBindAddress();
boolean found = false;
Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
for (Iterator<InternalDistributedMember> memberIter = hostedLocators.keySet().iterator(); memberIter.hasNext(); ) {
for (Iterator<String> locatorIter = hostedLocators.get(memberIter.next()).iterator(); locatorIter.hasNext(); ) {
DistributionLocatorId locator = new DistributionLocatorId(locatorIter.next());
found = found || locator.getHost().getHostAddress().equals(host);
found = found || locator.getHost().getHostName().equals(host);
if (!found && !host.contains(".")) {
try {
InetAddress inetAddr = InetAddress.getByName(host);
found = locator.getHost().getHostName().equals(inetAddr.getHostName());
if (!found) {
found = locator.getHost().getHostAddress().equals(inetAddr.getHostAddress());
}
} catch (UnknownHostException e) {
// try config host as if it is an IP address instead of host name
}
}
if (locator.getBindAddress() != null && !locator.getBindAddress().isEmpty() && bindAddress != null && !bindAddress.isEmpty()) {
found = found && locator.getBindAddress().equals(bindAddress);
}
found = found && locator.getPort() == port;
if (found) {
return true;
}
}
}
return found;
}
use of org.apache.geode.internal.admin.remote.DistributionLocatorId in project geode by apache.
the class WANTestBase method checkAllSiteMetaData.
public static void checkAllSiteMetaData(Map<Integer, Set<InetSocketAddress>> dsIdToLocatorAddresses) {
List<Locator> locatorsConfigured = Locator.getLocators();
Locator locator = locatorsConfigured.get(0);
Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> {
Map<Integer, Set<DistributionLocatorId>> allSiteMetaData = ((InternalLocator) locator).getlocatorMembershipListener().getAllLocatorsInfo();
for (Map.Entry<Integer, Set<InetSocketAddress>> entry : dsIdToLocatorAddresses.entrySet()) {
Set<DistributionLocatorId> foundLocatorIds = allSiteMetaData.get(entry.getKey());
Set<InetSocketAddress> expectedLocators = entry.getValue();
final Set<InetSocketAddress> foundLocators = foundLocatorIds.stream().map(distributionLocatorId -> new InetSocketAddress(distributionLocatorId.getHostnameForClients(), distributionLocatorId.getPort())).collect(Collectors.toSet());
assertEquals(expectedLocators, foundLocators);
}
});
}
Aggregations