Search in sources :

Example 11 with DistributionLocatorId

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);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId)

Example 12 with DistributionLocatorId

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();
        }
    }
}
Also used : DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) IOException(java.io.IOException)

Example 13 with DistributionLocatorId

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;
}
Also used : ConfigurationResponse(org.apache.geode.management.internal.configuration.messages.ConfigurationResponse) UnknownHostException(java.net.UnknownHostException) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) ConfigurationRequest(org.apache.geode.management.internal.configuration.messages.ConfigurationRequest) TcpClient(org.apache.geode.distributed.internal.tcpserver.TcpClient) IOException(java.io.IOException) ClusterConfigurationNotAvailableException(org.apache.geode.internal.process.ClusterConfigurationNotAvailableException) InetAddress(java.net.InetAddress)

Example 14 with DistributionLocatorId

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) DM(org.apache.geode.distributed.internal.DM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InetAddress(java.net.InetAddress)

Example 15 with DistributionLocatorId

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);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryEvent(org.apache.geode.cache.EntryEvent) CacheListener(org.apache.geode.cache.CacheListener) Arrays(java.util.Arrays) AttributesFactory(org.apache.geode.cache.AttributesFactory) OrderPolicy(org.apache.geode.cache.wan.GatewaySender.OrderPolicy) LocalRegion(org.apache.geode.internal.cache.LocalRegion) GATEWAY_SSL_KEYSTORE_TYPE(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_KEYSTORE_TYPE) GatewayEventFilter(org.apache.geode.cache.wan.GatewayEventFilter) GATEWAY_SSL_KEYSTORE(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_KEYSTORE) InetAddress(java.net.InetAddress) Cache(org.apache.geode.cache.Cache) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) CacheTestCase(org.apache.geode.cache30.CacheTestCase) Future(java.util.concurrent.Future) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) Map(java.util.Map) ConcurrentSerialGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.serial.ConcurrentSerialGatewaySenderEventProcessor) REMOTE_LOCATORS(org.apache.geode.distributed.ConfigurationProperties.REMOTE_LOCATORS) CacheServer(org.apache.geode.cache.server.CacheServer) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver) Scope(org.apache.geode.cache.Scope) LOCATORS(org.apache.geode.distributed.ConfigurationProperties.LOCATORS) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) Set(java.util.Set) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Serializable(java.io.Serializable) JUnit4DistributedTestCase(org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) Assert.assertFalse(org.junit.Assert.assertFalse) ConcurrentParallelGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderEventProcessor) GATEWAY_SSL_ENABLED(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_ENABLED) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) MCAST_PORT(org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT) Awaitility(org.awaitility.Awaitility) GATEWAY_SSL_CIPHERS(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_CIPHERS) GATEWAY_SSL_PROTOCOLS(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_PROTOCOLS) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) CacheFactory(org.apache.geode.cache.CacheFactory) Callable(java.util.concurrent.Callable) AttributesMutator(org.apache.geode.cache.AttributesMutator) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Host(org.apache.geode.test.dunit.Host) VM(org.apache.geode.test.dunit.VM) RegionQueue(org.apache.geode.internal.cache.RegionQueue) ArrayList(java.util.ArrayList) LogWriterUtils(org.apache.geode.test.dunit.LogWriterUtils) Region(org.apache.geode.cache.Region) StringTokenizer(java.util.StringTokenizer) START_LOCATOR(org.apache.geode.distributed.ConfigurationProperties.START_LOCATOR) CacheConfig(org.apache.geode.internal.cache.CacheConfig) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) Properties(java.util.Properties) Assert.assertTrue(org.junit.Assert.assertTrue) GATEWAY_SSL_TRUSTSTORE_PASSWORD(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_TRUSTSTORE_PASSWORD) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) TestUtil(org.apache.geode.util.test.TestUtil) File(java.io.File) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) ExecutionException(java.util.concurrent.ExecutionException) GatewayQueueEvent(org.apache.geode.cache.wan.GatewayQueueEvent) Assert.assertNull(org.junit.Assert.assertNull) GatewayReceiverFactory(org.apache.geode.cache.wan.GatewayReceiverFactory) GATEWAY_SSL_TRUSTSTORE(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_TRUSTSTORE) CacheServerTestUtil(org.apache.geode.internal.cache.tier.sockets.CacheServerTestUtil) Assert.assertEquals(org.junit.Assert.assertEquals) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Customer(org.apache.geode.internal.cache.execute.data.Customer) CONSERVE_SOCKETS(org.apache.geode.distributed.ConfigurationProperties.CONSERVE_SOCKETS) Wait(org.apache.geode.test.dunit.Wait) LOG_LEVEL(org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL) AvailablePort(org.apache.geode.internal.AvailablePort) RegionAttributes(org.apache.geode.cache.RegionAttributes) ParallelGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderEventProcessor) Assert(org.apache.geode.test.dunit.Assert) CustomerIDPartitionResolver(org.apache.geode.internal.cache.CustomerIDPartitionResolver) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerialGatewaySenderQueue(org.apache.geode.internal.cache.wan.serial.SerialGatewaySenderQueue) Assert.fail(org.junit.Assert.fail) ThreadFactory(java.util.concurrent.ThreadFactory) JMX_MANAGER(org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER) PoolManager(org.apache.geode.cache.client.PoolManager) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) GATEWAY_SSL_KEYSTORE_PASSWORD(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_KEYSTORE_PASSWORD) OFF_HEAP_MEMORY_SIZE(org.apache.geode.distributed.ConfigurationProperties.OFF_HEAP_MEMORY_SIZE) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) JMX_MANAGER_HTTP_PORT(org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_HTTP_PORT) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) List(java.util.List) Invoke(org.apache.geode.test.dunit.Invoke) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) SimpleClass(org.apache.geode.pdx.SimpleClass) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) IgnoredException(org.apache.geode.test.dunit.IgnoredException) JMX_MANAGER_PORT(org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT) LocatorDiscoveryCallbackAdapter(org.apache.geode.cache.client.internal.LocatorDiscoveryCallbackAdapter) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) DiskStore(org.apache.geode.cache.DiskStore) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) HashMap(java.util.HashMap) DISTRIBUTED_SYSTEM_ID(org.apache.geode.distributed.ConfigurationProperties.DISTRIBUTED_SYSTEM_ID) HashSet(java.util.HashSet) GatewaySenderFactory(org.apache.geode.cache.wan.GatewaySenderFactory) CacheClosedException(org.apache.geode.cache.CacheClosedException) LocatorMembershipListener(org.apache.geode.cache.client.internal.locator.wan.LocatorMembershipListener) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) GatewayTransportFilter(org.apache.geode.cache.wan.GatewayTransportFilter) RegionFactory(org.apache.geode.cache.RegionFactory) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Pool(org.apache.geode.cache.client.Pool) Locator(org.apache.geode.distributed.Locator) Iterator(java.util.Iterator) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Assert.assertNotNull(org.junit.Assert.assertNotNull) GATEWAY_SSL_REQUIRE_AUTHENTICATION(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_REQUIRE_AUTHENTICATION) AvailablePortHelper(org.apache.geode.internal.AvailablePortHelper) AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) JMX_MANAGER_START(org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START) CustId(org.apache.geode.internal.cache.execute.data.CustId) Order(org.apache.geode.internal.cache.execute.data.Order) ParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue) TimeUnit(java.util.concurrent.TimeUnit) DataPolicy(org.apache.geode.cache.DataPolicy) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) GatewaySender(org.apache.geode.cache.wan.GatewaySender) Collections(java.util.Collections) SimpleClass1(org.apache.geode.pdx.SimpleClass1) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Locator(org.apache.geode.distributed.Locator) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) InetSocketAddress(java.net.InetSocketAddress) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DistributionLocatorId (org.apache.geode.internal.admin.remote.DistributionLocatorId)16 IOException (java.io.IOException)5 StringTokenizer (java.util.StringTokenizer)5 InetAddress (java.net.InetAddress)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 UnknownHostException (java.net.UnknownHostException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 LocatorMembershipListener (org.apache.geode.cache.client.internal.locator.wan.LocatorMembershipListener)2 Locator (org.apache.geode.distributed.Locator)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2 File (java.io.File)1 Serializable (java.io.Serializable)1 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1