Search in sources :

Example 1 with ClusterProxyWebApplicationException

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

the class JaxRSUtilTest method testClusterProxyError.

@Test
public void testClusterProxyError() {
    when(response.getStatusInfo()).thenReturn(statusType);
    when(statusType.getFamily()).thenReturn(Family.SERVER_ERROR);
    when(statusType.getStatusCode()).thenReturn(599);
    when(statusType.getReasonPhrase()).thenReturn("Network connect timeout");
    when(response.readEntity(any(Class.class))).thenReturn("{\"status\":599,\"code\":\"cluster-proxy.proxy.timeout\",\"message\":" + "\"Connect timeout of Some(10 seconds) expired\",\"retryable\":true}");
    WebApplicationException cpException = assertThrows(ClusterProxyWebApplicationException.class, () -> JaxRSUtil.response(response, GenericResponses.class));
    assertTrue(cpException instanceof ClusterProxyWebApplicationException);
    when(response.readEntity(any(Class.class))).thenReturn("{\"status\":599,\"code\":\"cluster-proxy.proxy.timeout\",\"message\":" + "\"Connect timeout of Some(10 seconds) expired\",\"retryable\":false}");
    cpException = assertThrows(WebApplicationException.class, () -> JaxRSUtil.response(response, GenericResponses.class));
    assertFalse(cpException instanceof ClusterProxyWebApplicationException);
    when(response.readEntity(any(Class.class))).thenReturn("{\"random\":true}");
    cpException = assertThrows(WebApplicationException.class, () -> JaxRSUtil.response(response, GenericResponses.class));
    assertFalse(cpException instanceof ClusterProxyWebApplicationException);
    when(response.readEntity(any(Class.class))).thenReturn("not a json");
    cpException = assertThrows(WebApplicationException.class, () -> JaxRSUtil.response(response, GenericResponses.class));
    assertFalse(cpException instanceof ClusterProxyWebApplicationException);
}
Also used : ClusterProxyWebApplicationException(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) ClusterProxyWebApplicationException(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException) Test(org.junit.Test)

Example 2 with ClusterProxyWebApplicationException

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException 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)

Aggregations

ClusterProxyWebApplicationException (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ClusterProxyError (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyError)1 GenericResponses (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)1 Test (org.junit.Test)1