Search in sources :

Example 16 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 17 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 18 with ServerConnectivityException

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

the class ServerFunctionExecutor method executeOnServer.

private ResultCollector executeOnServer(Function function, ResultCollector rc, byte hasResult) {
    FunctionStats stats = FunctionStats.getFunctionStats(function.getId());
    try {
        validateExecution(function, null);
        long start = stats.startTime();
        stats.startFunctionExecution(true);
        ExecuteFunctionOp.execute(this.pool, function, this, args, memberMappedArg, this.allServers, hasResult, rc, this.isFnSerializationReqd, UserAttributes.userAttributes.get(), groups);
        stats.endFunctionExecution(start, true);
        rc.endResults();
        return rc;
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(true);
        throw functionException;
    } catch (ServerConnectivityException exception) {
        throw exception;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(true);
        throw new FunctionException(exception);
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException)

Example 19 with ServerConnectivityException

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

the class ServerFunctionExecutor method executeOnServerNoAck.

private void executeOnServerNoAck(String functionId, byte hasResult, boolean isHA, boolean optimizeForWrite) {
    FunctionStats stats = FunctionStats.getFunctionStats(functionId);
    try {
        validateExecution(null, null);
        long start = stats.startTime();
        stats.startFunctionExecution(false);
        ExecuteFunctionNoAckOp.execute(this.pool, functionId, args, memberMappedArg, this.allServers, hasResult, this.isFnSerializationReqd, isHA, optimizeForWrite, groups);
        stats.endFunctionExecution(start, false);
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(false);
        throw functionException;
    } catch (ServerConnectivityException exception) {
        throw exception;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(false);
        throw new FunctionException(exception);
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException)

Example 20 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)

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