Search in sources :

Example 1 with ClusterProxyError

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError in project cloudbreak by hortonworks.

the class ClusterProxyErrorRpcListener method deserializeAsClusterProxyError.

private Optional<ClusterProxyError> deserializeAsClusterProxyError(ObjectNode objectNode) {
    ObjectMapper mapper = new ObjectMapper();
    ClusterProxyError clusterProxyError;
    try {
        clusterProxyError = mapper.treeToValue(objectNode, ClusterProxyError.class);
        if (!clusterProxyError.getCode().contains("cluster-proxy")) {
            return Optional.empty();
        }
    } catch (Exception ex) {
        return Optional.empty();
    }
    return Optional.of(clusterProxyError);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ClusterProxyException(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyException) ClusterProxyError(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError)

Example 2 with ClusterProxyError

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError in project cloudbreak by hortonworks.

the class FreeIpaHealthCheckClusterProxyErrorRpcListenerTest method testClusterProxyNotAClusterProxyError.

@Test
public void testClusterProxyNotAClusterProxyError() throws IOException {
    ClusterProxyError clusterProxyError = new ClusterProxyError("status", "error from something other than cluster proxy", "message", true);
    Response response = mock(Response.class);
    when(response.readEntity(any(Class.class))).thenReturn(clusterProxyError);
    assertDoesNotThrow(() -> {
        clusterProxyErrorRpcListener.onBeforeResponseProcessed(response);
    });
}
Also used : Response(javax.ws.rs.core.Response) ClusterProxyError(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError) Test(org.junit.Test)

Example 3 with ClusterProxyError

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError in project cloudbreak by hortonworks.

the class JaxRSUtil method handleUnexpectedError.

private static WebApplicationException handleUnexpectedError(Response response) {
    String textResponse = response.readEntity(String.class);
    LOGGER.debug("Received error: {}", textResponse);
    String errorMessage = transformErrorMessage(textResponse);
    String errormsg = "Status: " + response.getStatusInfo().getStatusCode() + ' ' + response.getStatusInfo().getReasonPhrase() + " Response: " + errorMessage;
    try {
        if (JsonUtil.isValid(errorMessage)) {
            ClusterProxyError clusterProxyError = JsonUtil.jsonToType(errorMessage, ClusterProxyErrorTypeReference.get());
            if (clusterProxyError.getRetryable()) {
                return new ClusterProxyWebApplicationException(errormsg, clusterProxyError);
            }
        }
    } catch (IllegalArgumentException e) {
        LOGGER.trace("Error message is not a json or not a cluster proxy error, thus we cannot parse it.", e);
    }
    return new WebApplicationException(errormsg);
}
Also used : ClusterProxyWebApplicationException(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) ClusterProxyWebApplicationException(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException) ClusterProxyError(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError)

Example 4 with ClusterProxyError

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError in project cloudbreak by hortonworks.

the class FreeIpaHealthCheckClusterProxyErrorRpcListenerTest method testClusterProxyError.

@Test
public void testClusterProxyError() throws IOException {
    ClusterProxyError clusterProxyError = new ClusterProxyError("status", "cluster-proxy.proxy.timeout", "message", true);
    Response response = mock(Response.class);
    when(response.readEntity(any(Class.class))).thenReturn(clusterProxyError);
    assertThrows(ClusterProxyException.class, () -> {
        clusterProxyErrorRpcListener.onBeforeResponseProcessed(response);
    });
}
Also used : Response(javax.ws.rs.core.Response) ClusterProxyError(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError) Test(org.junit.Test)

Aggregations

ClusterProxyError (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError)4 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ClusterProxyException (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyException)1 ClusterProxyWebApplicationException (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1