Search in sources :

Example 11 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class LocatorUDPSecurityDUnitTest method testLocatorWithUDPSecurityButServer.

@Test
public void testLocatorWithUDPSecurityButServer() throws Exception {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    DistributedTestUtils.deleteLocatorStateFile(port1);
    final String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]";
    vm0.invoke("Start locator " + locators, () -> startLocator(port));
    try {
        Properties props = new Properties();
        props.setProperty(MCAST_PORT, "0");
        props.setProperty(LOCATORS, locators);
        props.setProperty(MEMBER_TIMEOUT, "1000");
        // addDSProps(props);
        system = (InternalDistributedSystem) DistributedSystem.connect(props);
    } catch (GemFireConfigException gce) {
        Assert.assertTrue(gce.getMessage().contains("Rejecting findCoordinatorRequest"));
    } finally {
        vm0.invoke(() -> stopLocator());
    }
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) Properties(java.util.Properties) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 12 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class MembershipJUnitTest method testMulticastDiscoveryNotAllowed.

@Test
public void testMulticastDiscoveryNotAllowed() {
    Properties nonDefault = new Properties();
    nonDefault.put(DISABLE_TCP, "true");
    nonDefault.put(MCAST_PORT, "12345");
    nonDefault.put(LOG_FILE, "");
    nonDefault.put(LOG_LEVEL, "fine");
    nonDefault.put(LOCATORS, "");
    DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
    RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    ServiceConfig serviceConfig = mock(ServiceConfig.class);
    when(serviceConfig.getDistributionConfig()).thenReturn(config);
    when(serviceConfig.getTransport()).thenReturn(transport);
    Services services = mock(Services.class);
    when(services.getConfig()).thenReturn(serviceConfig);
    GMSJoinLeave joinLeave = new GMSJoinLeave();
    try {
        joinLeave.init(services);
        throw new Error("expected a GemFireConfigException to be thrown because no locators are configured");
    } catch (GemFireConfigException e) {
    // expected
    }
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) GemFireConfigException(org.apache.geode.GemFireConfigException) GMSJoinLeave(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class JettyHelperJUnitTest method testSetPortNoBindAddress.

@Test
public void testSetPortNoBindAddress() throws Exception {
    final Server jetty;
    try {
        jetty = JettyHelper.initJetty(null, 8090, SSLConfigurationFactory.getSSLConfigForComponent(SecurableCommunicationChannel.WEB));
        assertNotNull(jetty);
        assertNotNull(jetty.getConnectors()[0]);
        assertEquals(8090, ((ServerConnector) jetty.getConnectors()[0]).getPort());
    } catch (GemFireConfigException e) {
        fail(e.getMessage());
    }
}
Also used : Server(org.eclipse.jetty.server.Server) GemFireConfigException(org.apache.geode.GemFireConfigException) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 14 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class LocatorDUnitTest method testNoLocator.

/**
   * Tests that attempting to connect to a distributed system in which no locator is defined throws
   * an exception.
   */
@Test
public void testNoLocator() {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    DistributedTestUtils.deleteLocatorStateFile(port1);
    String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]";
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, locators);
    addDSProps(props);
    final String expected = "java.net.ConnectException";
    final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
    bgexecLogger.info(addExpected);
    boolean exceptionOccurred = true;
    try {
        DistributedSystem.connect(props);
        exceptionOccurred = false;
    } catch (DistributionException ex) {
    // I guess it can throw this too...
    } catch (GemFireConfigException ex) {
        String s = ex.getMessage();
        assertTrue(s.indexOf("Locator does not exist") >= 0);
    } catch (Exception ex) {
        // if you see this fail, determine if unexpected exception is expected
        // if expected then add in a catch block for it above this catch
        org.apache.geode.test.dunit.Assert.fail("Failed with unexpected exception", ex);
    } finally {
        bgexecLogger.info(removeExpected);
    }
    if (!exceptionOccurred) {
        fail("Should have thrown a GemFireConfigException");
    }
}
Also used : LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) GemFireConfigException(org.apache.geode.GemFireConfigException) Host(org.apache.geode.test.dunit.Host) DistributionException(org.apache.geode.distributed.internal.DistributionException) Properties(java.util.Properties) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) DistributionException(org.apache.geode.distributed.internal.DistributionException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 15 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class QueueManagerImpl method initializeConnections.

private void initializeConnections() {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("SubscriptionManager - intitializing connections");
    }
    int queuesNeeded = redundancyLevel == -1 ? -1 : redundancyLevel + 1;
    Set excludedServers = new HashSet(blackList.getBadServers());
    List servers = findQueueServers(excludedServers, queuesNeeded, true, false, null);
    if (servers == null || servers.isEmpty()) {
        logger.warn(LocalizedStrings.QueueManagerImpl_COULD_NOT_CREATE_A_QUEUE_NO_QUEUE_SERVERS_AVAILABLE);
        scheduleRedundancySatisfierIfNeeded(redundancyRetryInterval);
        synchronized (lock) {
            queueConnections = queueConnections.setPrimaryDiscoveryFailed(null);
            lock.notifyAll();
        }
        return;
    }
    if (isDebugEnabled) {
        logger.debug("SubscriptionManager - discovered subscription servers {}", servers);
    }
    SortedMap /* <ServerQueueStatus,Connection> */
    oldQueueServers = new TreeMap(QSIZE_COMPARATOR);
    List nonRedundantServers = new ArrayList();
    for (Iterator itr = servers.iterator(); itr.hasNext(); ) {
        ServerLocation server = (ServerLocation) itr.next();
        Connection connection = null;
        try {
            connection = factory.createClientToServerConnection(server, true);
        } catch (GemFireSecurityException e) {
            throw e;
        } catch (GemFireConfigException e) {
            throw e;
        } catch (Exception e) {
            if (isDebugEnabled) {
                logger.debug("SubscriptionManager - Error connected to server: {}", server, e);
            }
        }
        if (connection != null) {
            ServerQueueStatus status = connection.getQueueStatus();
            if (status.isRedundant() || status.isPrimary()) {
                oldQueueServers.put(status, connection);
            } else {
                nonRedundantServers.add(connection);
            }
        }
    }
    // This ordering was determined from the old ConnectionProxyImpl code
    //
    // initialization order of the new redundant and primary server is
    // old redundant w/ second largest queue
    // old redundant w/ third largest queue
    // ...
    // old primary
    // non redundants in no particular order
    //
    // The primary is then chosen as
    // redundant with the largest queue
    // primary if there are no redundants
    // a non redundant
    // if the redundant with the largest queue fails, then we go and
    // make a new server a primary.
    Connection newPrimary = null;
    if (!oldQueueServers.isEmpty()) {
        newPrimary = (Connection) oldQueueServers.remove(oldQueueServers.lastKey());
    } else if (!nonRedundantServers.isEmpty()) {
        newPrimary = (Connection) nonRedundantServers.remove(0);
    }
    nonRedundantServers.addAll(0, oldQueueServers.values());
    for (Iterator itr = nonRedundantServers.iterator(); itr.hasNext(); ) {
        Connection connection = (Connection) itr.next();
        QueueConnectionImpl queueConnection = initializeQueueConnection(connection, false, null);
        if (queueConnection != null) {
            addToConnectionList(queueConnection, false);
        }
    }
    QueueConnectionImpl primaryQueue = null;
    if (newPrimary != null) {
        primaryQueue = initializeQueueConnection(newPrimary, true, null);
        if (primaryQueue == null) {
            newPrimary.destroy();
        } else {
            if (!addToConnectionList(primaryQueue, true)) {
                primaryQueue = null;
            }
        }
    }
    excludedServers.addAll(servers);
    // above.
    if (redundancyLevel != -1 && getCurrentRedundancy() < redundancyLevel) {
        if (isDebugEnabled) {
            logger.debug("SubscriptionManager - Some initial connections failed. Trying to create redundant queues");
        }
        recoverRedundancy(excludedServers, false);
    }
    if (redundancyLevel != -1 && primaryQueue == null) {
        if (isDebugEnabled) {
            logger.debug("SubscriptionManager - Intial primary creation failed. Trying to create a new primary");
        }
        while (primaryQueue == null) {
            primaryQueue = createNewPrimary(excludedServers);
            if (primaryQueue == null) {
                // couldn't find a server to make primary
                break;
            }
            if (!addToConnectionList(primaryQueue, true)) {
                excludedServers.add(primaryQueue.getServer());
                primaryQueue = null;
            }
        }
    }
    if (primaryQueue == null) {
        if (isDebugEnabled) {
            logger.debug("SubscriptionManager - Unable to create a new primary queue, using one of the redundant queues");
        }
        while (primaryQueue == null) {
            primaryQueue = promoteBackupToPrimary(queueConnections.getBackups());
            if (primaryQueue == null) {
                // no backup servers available
                break;
            }
            if (!addToConnectionList(primaryQueue, true)) {
                synchronized (lock) {
                    // make sure we don't retry this same connection.
                    queueConnections = queueConnections.removeConnection(primaryQueue);
                }
                primaryQueue = null;
            }
        }
    }
    if (primaryQueue == null) {
        logger.error(LocalizedMessage.create(LocalizedStrings.QueueManagerImpl_COULD_NOT_INITIALIZE_A_PRIMARY_QUEUE_ON_STARTUP_NO_QUEUE_SERVERS_AVAILABLE));
        synchronized (lock) {
            queueConnections = queueConnections.setPrimaryDiscoveryFailed(new NoSubscriptionServersAvailableException(LocalizedStrings.QueueManagerImpl_COULD_NOT_INITIALIZE_A_PRIMARY_QUEUE_ON_STARTUP_NO_QUEUE_SERVERS_AVAILABLE.toLocalizedString()));
            lock.notifyAll();
        }
        cqsDisconnected();
    } else {
        cqsConnected();
    }
    if (getCurrentRedundancy() < redundancyLevel) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.QueueManagerImpl_UNABLE_TO_INITIALIZE_ENOUGH_REDUNDANT_QUEUES_ON_STARTUP_THE_REDUNDANCY_COUNT_IS_CURRENTLY_0, getCurrentRedundancy()));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireException(org.apache.geode.GemFireException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireConfigException(org.apache.geode.GemFireConfigException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireConfigException(org.apache.geode.GemFireConfigException) SortedMap(java.util.SortedMap) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ServerQueueStatus(org.apache.geode.internal.cache.tier.sockets.ServerQueueStatus) HashSet(java.util.HashSet)

Aggregations

GemFireConfigException (org.apache.geode.GemFireConfigException)28 IOException (java.io.IOException)11 SystemConnectException (org.apache.geode.SystemConnectException)10 Properties (java.util.Properties)7 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)7 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)6 Test (org.junit.Test)6 UnknownHostException (java.net.UnknownHostException)5 CancelException (org.apache.geode.CancelException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 InetSocketAddress (java.net.InetSocketAddress)4 GemFireIOException (org.apache.geode.GemFireIOException)4 VersionedDataInputStream (org.apache.geode.internal.VersionedDataInputStream)4 MemberShunnedException (org.apache.geode.internal.tcp.MemberShunnedException)4 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)4 InputStream (java.io.InputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ServerSocket (java.net.ServerSocket)3 NetView (org.apache.geode.distributed.internal.membership.NetView)3