use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class SecurityTestUtils method doPutsP.
private static void doPutsP(final int num, final int multiUserIndex, final int expectedResult, final boolean newVals) {
assertTrue(num <= KEYS.length);
Region region = getRegion(multiUserIndex, expectedResult);
for (int index = 0; index < num; ++index) {
try {
if (newVals) {
region.put(KEYS[index], NVALUES[index]);
} else {
region.put(KEYS[index], VALUES[index]);
}
if (expectedResult != NO_EXCEPTION) {
fail("Expected a NotAuthorizedException while doing puts");
}
} catch (NoAvailableServersException ex) {
if (expectedResult == NO_AVAILABLE_SERVERS) {
getLogWriter().info("Got expected NoAvailableServers when doing puts: " + ex.getCause());
continue;
} else {
fail("Got unexpected exception when doing puts", ex);
}
} catch (ServerConnectivityException ex) {
if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
getLogWriter().info("Got expected NotAuthorizedException when doing puts: " + ex.getCause());
continue;
}
if ((expectedResult == AUTHREQ_EXCEPTION) && (ex.getCause() instanceof AuthenticationRequiredException)) {
getLogWriter().info("Got expected AuthenticationRequiredException when doing puts: " + ex.getCause());
continue;
}
if ((expectedResult == AUTHFAIL_EXCEPTION) && (ex.getCause() instanceof AuthenticationFailedException)) {
getLogWriter().info("Got expected AuthenticationFailedException when doing puts: " + ex.getCause());
continue;
} else if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when doing puts: " + ex);
} else {
fail("Got unexpected exception when doing puts", ex);
}
} catch (Exception ex) {
if (expectedResult == OTHER_EXCEPTION) {
getLogWriter().info("Got expected exception when doing puts: " + ex);
} else {
fail("Got unexpected exception when doing puts", ex);
}
}
}
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ClientServerFunctionExecutionDUnitTest method serverExecutionNonHA.
public static Object serverExecutionNonHA(Boolean isByName, Function function, Boolean toRegister) {
DistributedSystem.setThreadsSocketPolicy(false);
if (toRegister.booleanValue()) {
FunctionService.registerFunction(function);
}
Execution member = FunctionService.onServer(pool);
try {
ArrayList<String> args = new ArrayList<String>();
args.add(retryRegionName);
args.add("serverExecutionNonHA");
ResultCollector rs = execute(member, args, function, isByName);
fail("Expected ServerConnectivityException not thrown!");
} catch (Exception ex) {
if (!(ex instanceof ServerConnectivityException)) {
ex.printStackTrace();
LogWriterUtils.getLogWriter().info("Exception : ", ex);
fail("Test failed after the execute operation");
}
}
return null;
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ClientServerFunctionExecutionDUnitTest method serverExecutionHATwoServerDown.
public static void serverExecutionHATwoServerDown(Boolean isByName, Function function, Boolean toRegister) {
DistributedSystem.setThreadsSocketPolicy(false);
if (toRegister.booleanValue()) {
FunctionService.registerFunction(function);
}
Execution member = FunctionService.onServer(pool);
try {
ArrayList<String> args = new ArrayList<String>();
args.add(retryRegionName);
args.add("serverExecutionHATwoServerDown");
ResultCollector rs = execute(member, args, function, isByName);
fail("Expected ServerConnectivityException not thrown!");
} catch (Exception ex) {
if (!(ex instanceof ServerConnectivityException)) {
ex.printStackTrace();
LogWriterUtils.getLogWriter().info("Exception : ", ex);
fail("Test failed after the execute operation");
}
}
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class GatewaySenderEventRemoteDispatcher method initializeConnection.
/**
* Initializes the <code>Connection</code>.
*
* @throws GatewaySenderException
*/
private void initializeConnection() throws GatewaySenderException, GemFireSecurityException {
this.connectionLifeCycleLock.writeLock().lock();
try {
// Attempt to acquire a connection
if (this.sender.getProxy() == null || this.sender.getProxy().isDestroyed()) {
this.sender.initProxy();
} else {
this.processor.resetBatchId();
}
Connection con;
try {
if (this.sender.isParallel()) {
/*
* TODO - The use of acquireConnection should be removed from the gateway code. This
* method is fine for tests, but these connections should really be managed inside the
* pool code. If the gateway needs to persistent connection to a single server, which
* should create have the OpExecutor that holds a reference to the connection (similar to
* the way we do with thread local connections). Use {@link
* ExecutablePool#setupServerAffinity(boolean)} for gateway code
*/
con = this.sender.getProxy().acquireConnection();
// For parallel sender, setting server location will not matter.
// everytime it will ask for acquire connection whenever it needs it. I
// am saving this server location for command purpose
sender.setServerLocation(con.getServer());
} else {
synchronized (this.sender.getLockForConcurrentDispatcher()) {
ServerLocation server = this.sender.getServerLocation();
if (server != null) {
if (logger.isDebugEnabled()) {
logger.debug("ServerLocation is: {}. Connecting to this serverLocation...", server);
}
con = this.sender.getProxy().acquireConnection(server);
} else {
if (logger.isDebugEnabled()) {
logger.debug("ServerLocation is null. Creating new connection. ");
}
con = this.sender.getProxy().acquireConnection();
// PRIMARY
if (this.sender.isPrimary()) {
if (sender.getServerLocation() == null) {
sender.setServerLocation(con.getServer());
}
new UpdateAttributesProcessor(this.sender).distribute(false);
}
}
}
}
} catch (ServerConnectivityException e) {
this.failedConnectCount++;
Throwable ex = null;
if (e.getCause() instanceof GemFireSecurityException) {
ex = e.getCause();
if (logConnectionFailure()) {
// only log this message once; another msg is logged once we connect
logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_COULD_NOT_CONNECT_1, new Object[] { this.processor.getSender().getId(), ex.getMessage() }));
}
throw new GatewaySenderException(ex);
}
List<ServerLocation> servers = this.sender.getProxy().getCurrentServers();
String ioMsg = null;
if (servers.size() == 0) {
ioMsg = LocalizedStrings.GatewayEventRemoteDispatcher_THERE_ARE_NO_ACTIVE_SERVERS.toLocalizedString();
} else {
final StringBuilder buffer = new StringBuilder();
for (ServerLocation server : servers) {
String endpointName = String.valueOf(server);
if (buffer.length() > 0) {
buffer.append(", ");
}
buffer.append(endpointName);
}
ioMsg = LocalizedStrings.GatewayEventRemoteDispatcher_NO_AVAILABLE_CONNECTION_WAS_FOUND_BUT_THE_FOLLOWING_ACTIVE_SERVERS_EXIST_0.toLocalizedString(buffer.toString());
}
ex = new IOException(ioMsg);
// Set the serverLocation to null so that a new connection can be
// obtained in next attempt
this.sender.setServerLocation(null);
if (this.failedConnectCount == 1) {
// only log this message once; another msg is logged once we connect
logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT, this.processor.getSender().getId()));
}
// same as the other exceptions that might occur in sendBatch.
throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT.toLocalizedString(this.processor.getSender().getId()), ex);
}
if (this.failedConnectCount > 0) {
Object[] logArgs = new Object[] { this.processor.getSender().getId(), con, Integer.valueOf(this.failedConnectCount) };
logger.info(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_USING_1_AFTER_2_FAILED_CONNECT_ATTEMPTS, logArgs));
this.failedConnectCount = 0;
} else {
Object[] logArgs = new Object[] { this.processor.getSender().getId(), con };
logger.info(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_0_USING_1, logArgs));
}
this.connection = con;
this.processor.checkIfPdxNeedsResend(this.connection.getQueueStatus().getPdxSize());
} catch (ConnectionDestroyedException e) {
throw new GatewaySenderException(LocalizedStrings.GatewayEventRemoteDispatcher__0___COULD_NOT_CONNECT.toLocalizedString(this.processor.getSender().getId()), e);
} finally {
this.connectionLifeCycleLock.writeLock().unlock();
}
}
Aggregations