Search in sources :

Example 6 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class AbstractOp method sendMessage.

/**
   * New implementations of AbstractOp should override this method if the implementation should be
   * excluded from client authentication. e.g. PingOp#sendMessage(Connection cnx)
   * 
   * @see AbstractOp#needsUserId()
   * @see AbstractOp#processSecureBytes(Connection, Message)
   * @see ServerConnection#updateAndGetSecurityPart()
   */
protected void sendMessage(Connection cnx) throws Exception {
    if (cnx.getServer().getRequiresCredentials()) {
        // Security is enabled on client as well as on server
        getMessage().setMessageHasSecurePartFlag();
        long userId = -1;
        if (UserAttributes.userAttributes.get() == null) {
            // single user mode
            userId = cnx.getServer().getUserId();
        } else {
            // multi user mode
            Object id = UserAttributes.userAttributes.get().getServerToId().get(cnx.getServer());
            if (id == null) {
                // the retryCount is exhausted. Fix for Bug 41501
                throw new ServerConnectivityException("Connection error while authenticating user");
            }
            userId = (Long) id;
        }
        HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
        try {
            hdos.writeLong(cnx.getConnectionID());
            hdos.writeLong(userId);
            getMessage().setSecurePart(((ConnectionImpl) cnx).getHandShake().encryptBytes(hdos.toByteArray()));
        } finally {
            hdos.close();
        }
    }
    getMessage().send(false);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream)

Example 7 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class ConnectionPoolImplJUnitTest method testExecuteOp.

@Test
public void testExecuteOp() throws Exception {
    CacheServer server1 = cache.addCacheServer();
    CacheServer server2 = cache.addCacheServer();
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    int port1 = ports[0];
    int port2 = ports[1];
    server1.setPort(port1);
    server2.setPort(port2);
    server1.start();
    server2.start();
    PoolFactory cpf = PoolManager.createFactory();
    cpf.addServer("localhost", port2);
    cpf.addServer("localhost", port1);
    PoolImpl pool = (PoolImpl) cpf.create("pool1");
    ServerLocation location1 = new ServerLocation("localhost", port1);
    ServerLocation location2 = new ServerLocation("localhost", port2);
    Op testOp = new Op() {

        int attempts = 0;

        public Object attempt(Connection cnx) throws Exception {
            if (attempts == 0) {
                attempts++;
                throw new SocketTimeoutException();
            } else {
                return cnx.getServer();
            }
        }

        @Override
        public boolean useThreadLocalConnection() {
            return true;
        }
    };
    // TODO - set retry attempts, and throw in some assertions
    // about how many times we retry
    ServerLocation usedServer = (ServerLocation) pool.execute(testOp);
    assertTrue("expected " + location1 + " or " + location2 + ", got " + usedServer, location1.equals(usedServer) || location2.equals(usedServer));
    testOp = new Op() {

        public Object attempt(Connection cnx) throws Exception {
            throw new SocketTimeoutException();
        }

        @Override
        public boolean useThreadLocalConnection() {
            return true;
        }
    };
    try {
        usedServer = (ServerLocation) pool.execute(testOp);
        fail("Should have failed");
    } catch (ServerConnectivityException expected) {
    // do nothing
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SocketTimeoutException(java.net.SocketTimeoutException) PoolFactory(org.apache.geode.cache.client.PoolFactory) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SocketTimeoutException(java.net.SocketTimeoutException) CacheServer(org.apache.geode.cache.server.CacheServer) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class ClientTypeRegistration method getType.

public PdxType getType(int typeId) {
    Collection<Pool> pools = getAllPools();
    ServerConnectivityException lastException = null;
    for (Pool pool : pools) {
        try {
            PdxType type = GetPDXTypeByIdOp.execute((ExecutablePool) pool, typeId);
            if (type != null) {
                return type;
            }
        } catch (ServerConnectivityException e) {
            logger.debug("Received an exception getting pdx type from pool {}, {}", pool, e.getMessage(), e);
            // ignore, try the next pool.
            lastException = e;
        }
    }
    if (lastException != null) {
        throw lastException;
    } else {
        throw returnCorrectExceptionForFailure(pools, typeId, lastException);
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ExecutablePool(org.apache.geode.cache.client.internal.ExecutablePool) Pool(org.apache.geode.cache.client.Pool)

Example 9 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class ClientTypeRegistration method addImportedType.

@Override
public void addImportedType(int typeId, PdxType importedType) {
    Collection<Pool> pools = getAllPools();
    ServerConnectivityException lastException = null;
    for (Pool pool : pools) {
        try {
            sendTypeToPool(importedType, typeId, pool);
        } catch (ServerConnectivityException e) {
            lastException = e;
            break;
        }
    }
    if (lastException == null) {
        return;
    }
    throw returnCorrectExceptionForFailure(pools, typeId, lastException);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ExecutablePool(org.apache.geode.cache.client.internal.ExecutablePool) Pool(org.apache.geode.cache.client.Pool)

Example 10 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class ClientTypeRegistration method defineType.

public int defineType(PdxType newType) {
    Collection<Pool> pools = getAllPools();
    ServerConnectivityException lastException = null;
    int newTypeId = -1;
    for (Pool pool : pools) {
        try {
            newTypeId = GetPDXIdForTypeOp.execute((ExecutablePool) pool, newType);
            newType.setTypeId(newTypeId);
            sendTypeToPool(newType, newTypeId, pool);
            return newTypeId;
        } catch (ServerConnectivityException e) {
            // ignore, try the next pool.
            lastException = e;
        }
    }
    throw returnCorrectExceptionForFailure(pools, newTypeId, lastException);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ExecutablePool(org.apache.geode.cache.client.internal.ExecutablePool) ExecutablePool(org.apache.geode.cache.client.internal.ExecutablePool) Pool(org.apache.geode.cache.client.Pool)

Aggregations

ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)44 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)25 FunctionException (org.apache.geode.cache.execute.FunctionException)17 IOException (java.io.IOException)16 Region (org.apache.geode.cache.Region)13 NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)13 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)12 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)10 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 CacheClosedException (org.apache.geode.cache.CacheClosedException)8 Pool (org.apache.geode.cache.client.Pool)6 ExecutablePool (org.apache.geode.cache.client.internal.ExecutablePool)6 Test (org.junit.Test)6 SocketTimeoutException (java.net.SocketTimeoutException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Execution (org.apache.geode.cache.execute.Execution)4