Search in sources :

Example 1 with ExternalServiceTimeoutException

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);
    }
}
Also used : ExternalServiceTimeoutException(org.apache.qpid.server.util.ExternalServiceTimeoutException) InputStream(java.io.InputStream) GeneralSecurityException(java.security.GeneralSecurityException) ExternalServiceException(org.apache.qpid.server.util.ExternalServiceException) ConnectionBuilder(org.apache.qpid.server.util.ConnectionBuilder) IOException(java.io.IOException) URL(java.net.URL) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) HttpURLConnection(java.net.HttpURLConnection) SocketTimeoutException(java.net.SocketTimeoutException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with ExternalServiceTimeoutException

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();
    }
}
Also used : ExternalServiceTimeoutException(org.apache.qpid.server.util.ExternalServiceTimeoutException) DaemonThreadFactory(org.apache.qpid.server.util.DaemonThreadFactory) ExternalServiceException(org.apache.qpid.server.util.ExternalServiceException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) Callable(java.util.concurrent.Callable) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Collection(java.util.Collection) ExecutionException(java.util.concurrent.ExecutionException) SocketTimeoutException(java.net.SocketTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) ExternalServiceTimeoutException(org.apache.qpid.server.util.ExternalServiceTimeoutException)

Example 3 with ExternalServiceTimeoutException

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);
    }
}
Also used : ExternalServiceTimeoutException(org.apache.qpid.server.util.ExternalServiceTimeoutException) NodeState(com.sleepycat.je.rep.NodeState) BinaryProtocol(com.sleepycat.je.rep.utilint.BinaryProtocol) ExternalServiceException(org.apache.qpid.server.util.ExternalServiceException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) SocketTimeoutException(java.net.SocketTimeoutException) ServiceConnectFailedException(com.sleepycat.je.rep.utilint.ServiceDispatcher.ServiceConnectFailedException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Aggregations

SocketTimeoutException (java.net.SocketTimeoutException)3 ExternalServiceException (org.apache.qpid.server.util.ExternalServiceException)3 ExternalServiceTimeoutException (org.apache.qpid.server.util.ExternalServiceTimeoutException)3 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)3 IOException (java.io.IOException)2 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)2 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 NodeState (com.sleepycat.je.rep.NodeState)1 BinaryProtocol (com.sleepycat.je.rep.utilint.BinaryProtocol)1 ServiceConnectFailedException (com.sleepycat.je.rep.utilint.ServiceDispatcher.ServiceConnectFailedException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Collection (java.util.Collection)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1