use of org.apache.qpid.server.util.ExternalServiceTimeoutException in project qpid-broker-j by apache.
the class CloudFoundryDashboardManagementGroupProviderImpl method mayManageServiceInstance.
private boolean mayManageServiceInstance(final String serviceInstanceId, final String accessToken) {
HttpURLConnection connection;
String cloudFoundryEndpoint = String.format("%s/v2/service_instances/%s/permissions", getCloudFoundryEndpointURI().toString(), serviceInstanceId);
try {
ConnectionBuilder connectionBuilder = new ConnectionBuilder(new URL(cloudFoundryEndpoint));
connectionBuilder.setConnectTimeout(_connectTimeout).setReadTimeout(_readTimeout);
if (_trustStore != null) {
try {
connectionBuilder.setTrustMangers(_trustStore.getTrustManagers());
} catch (GeneralSecurityException e) {
throw new ServerScopedRuntimeException("Cannot initialise TLS", e);
}
}
connectionBuilder.setTlsProtocolAllowList(_tlsProtocolAllowList).setTlsProtocolDenyList(_tlsProtocolDenyList).setTlsCipherSuiteAllowList(_tlsCipherSuiteAllowList).setTlsCipherSuiteDenyList(_tlsCipherSuiteDenyList);
LOGGER.debug("About to call CloudFoundryDashboardManagementEndpoint '{}'", cloudFoundryEndpoint);
connection = connectionBuilder.build();
connection.setRequestProperty("Accept-Charset", UTF8);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Authorization", "Bearer " + accessToken);
connection.connect();
} catch (SocketTimeoutException e) {
throw new ExternalServiceTimeoutException(String.format("Timed out trying to connect to CloudFoundryDashboardManagementEndpoint '%s'.", cloudFoundryEndpoint), e);
} catch (IOException e) {
throw new ExternalServiceException(String.format("Could not connect to CloudFoundryDashboardManagementEndpoint '%s'.", cloudFoundryEndpoint), e);
}
try (InputStream input = connection.getInputStream()) {
final int responseCode = connection.getResponseCode();
LOGGER.debug("Call to CloudFoundryDashboardManagementEndpoint '{}' complete, response code : {}", cloudFoundryEndpoint, responseCode);
Map<String, Object> responseMap = _objectMapper.readValue(input, Map.class);
Object mayManageObject = responseMap.get("manage");
if (mayManageObject == null || !(mayManageObject instanceof Boolean)) {
throw new ExternalServiceException("CloudFoundryDashboardManagementEndpoint response did not contain \"manage\" entry.");
}
return (boolean) mayManageObject;
} catch (JsonProcessingException e) {
throw new ExternalServiceException(String.format("CloudFoundryDashboardManagementEndpoint '%s' did not return json.", cloudFoundryEndpoint), e);
} catch (SocketTimeoutException e) {
throw new ExternalServiceTimeoutException(String.format("Timed out reading from CloudFoundryDashboardManagementEndpoint '%s'.", cloudFoundryEndpoint), e);
} catch (IOException e) {
throw new ExternalServiceException(String.format("Connection to CloudFoundryDashboardManagementEndpoint '%s' failed.", cloudFoundryEndpoint), e);
}
}
use of org.apache.qpid.server.util.ExternalServiceTimeoutException in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method connectToHelperNodeAndCheckPermittedHosts.
public static Collection<String> connectToHelperNodeAndCheckPermittedHosts(final String nodeName, final String hostPort, final String groupName, final String helperNodeName, final String helperHostPort, final int dbPingSocketTimeout) {
ExecutorService executor = null;
Future<Collection<String>> future = null;
try {
executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory(String.format("PermittedHostsCheck-%s-%s", groupName, nodeName)));
future = executor.submit(new Callable<Collection<String>>() {
@Override
public Collection<String> call() throws Exception {
return getPermittedHostsFromHelper(nodeName, groupName, helperNodeName, helperHostPort, dbPingSocketTimeout);
}
});
try {
final long timeout = (long) (dbPingSocketTimeout * 1.25);
final Collection<String> permittedNodes = dbPingSocketTimeout <= 0 ? future.get() : future.get(timeout, TimeUnit.MILLISECONDS);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Node '%s' permits nodes: '%s'", helperNodeName, String.valueOf(permittedNodes)));
}
if (permittedNodes == null || !permittedNodes.contains(hostPort)) {
throw new IllegalConfigurationException(String.format("Node using address '%s' is not permitted to join the group '%s'", hostPort, groupName));
}
return permittedNodes;
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
throw new RuntimeException(cause);
}
} catch (TimeoutException e) {
future.cancel(true);
throw new ExternalServiceTimeoutException(String.format("Task timed out trying to connect to existing node '%s' at '%s'", nodeName, hostPort));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ExternalServiceException(String.format("Task failed to connect to existing node '%s' at '%s'", nodeName, hostPort));
}
} finally {
executor.shutdown();
}
}
use of org.apache.qpid.server.util.ExternalServiceTimeoutException in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method getPermittedHostsFromHelper.
private static Collection<String> getPermittedHostsFromHelper(final String nodeName, final String groupName, final String helperNodeName, final String helperHostPort, final int dbPingSocketTimeout) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Requesting state of the node '%s' at '%s'", helperNodeName, helperHostPort));
}
if (helperNodeName == null || "".equals(helperNodeName)) {
throw new IllegalConfigurationException(String.format("A helper node is not specified for node '%s'" + " joining the group '%s'", nodeName, groupName));
}
Collection<String> permittedNodes = null;
try {
ReplicationNodeImpl node = new ReplicationNodeImpl(helperNodeName, helperHostPort);
NodeState state = getRemoteNodeState(groupName, node, dbPingSocketTimeout);
byte[] applicationState = state.getAppState();
return convertApplicationStateBytesToPermittedNodeList(applicationState);
} catch (SocketTimeoutException ste) {
throw new ExternalServiceTimeoutException(String.format("Timed out trying to connect to existing node '%s' at '%s'", helperNodeName, helperHostPort), ste);
} catch (IOException | ServiceConnectFailedException e) {
throw new ExternalServiceException(String.format("Cannot connect to existing node '%s' at '%s'", helperNodeName, helperHostPort), e);
} catch (BinaryProtocol.ProtocolException e) {
String message = String.format("Unexpected protocol exception '%s' encountered while retrieving state for node '%s' (%s) from group '%s'", e.getUnexpectedMessage(), helperNodeName, helperHostPort, groupName);
LOGGER.warn(message, e);
throw new ExternalServiceException(message, e);
} catch (RuntimeException e) {
throw new ExternalServiceException(String.format("Cannot retrieve state for node '%s' (%s) from group '%s'", helperNodeName, helperHostPort, groupName), e);
}
}
Aggregations