Search in sources :

Example 1 with NeutronError

use of com.woorea.openstack.quantum.model.NeutronError in project so by onap.

the class MsoCommonUtils method neutronExceptionToMsoException.

/*
     * Convert an Openstack Exception on a Neutron call to an MsoOpenstackException. This method supports both
     * OpenstackResponseException and OpenStackConnectException.
     */
protected MsoException neutronExceptionToMsoException(OpenStackBaseException e, String context) {
    MsoException me = null;
    if (e instanceof OpenStackResponseException) {
        OpenStackResponseException re = (OpenStackResponseException) e;
        try {
            // Failed Neutron calls return an NeutronError entity body
            NeutronError error = re.getResponse().getErrorEntity(NeutronError.class);
            logger.error("{} {} Openstack Neutron Error on {} {}", MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.DataError.getValue(), context, error);
            me = new MsoOpenstackException(re.getStatus(), error.getType(), error.getMessage());
        } catch (Exception e2) {
            // Couldn't parse body as a NeutronError. Report the HTTP error.
            logger.error("{} {} Openstack HTTP Error on {}: {}, {}", MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.DataError.getValue(), context, re.getStatus(), e.getMessage(), e2);
            me = new MsoOpenstackException(re.getStatus(), re.getMessage(), null);
        }
        // Add the context of the error
        me.addContext(context);
        // Generate an alarm for 5XX and higher errors.
        if (re.getStatus() >= 500) {
            logger.error("{} {} OpenStackBaseException with response code {} on {}: ", MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.DataError.getValue(), re.getStatus(), context, e);
        }
    } else if (e instanceof OpenStackConnectException) {
        OpenStackConnectException ce = (OpenStackConnectException) e;
        me = new MsoIOException(ce.getMessage());
        me.addContext(context);
        // Generate an alarm for all connection errors.
        logger.error("{} {} Openstack Neutron Connection error on {}: ", MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.DataError.getValue(), context, e);
    }
    return me;
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) NeutronError(com.woorea.openstack.quantum.model.NeutronError) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) MsoIOException(org.onap.so.openstack.exceptions.MsoIOException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ServiceEndpointNotFoundException(org.onap.so.cloud.authentication.ServiceEndpointNotFoundException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) IOException(java.io.IOException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) MsoIOException(org.onap.so.openstack.exceptions.MsoIOException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException)

Example 2 with NeutronError

use of com.woorea.openstack.quantum.model.NeutronError in project so by onap.

the class MsoCommonUtilsTest method testNeutronExceptionToMsoException.

@Test
public final void testNeutronExceptionToMsoException() throws JsonParseException, JsonMappingException, IOException {
    OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
    OpenStackBaseException openStackResponseException = new OpenStackResponseException("response", 1);
    MsoException me = commonUtils.neutronExceptionToMsoException(openStackConnectException, "ContextError");
    assertTrue(me instanceof MsoIOException);
    assertTrue("connect".equals(me.getMessage()));
    MsoException me2 = commonUtils.neutronExceptionToMsoException(openStackResponseException, "ContextError");
    assertTrue(me2 instanceof MsoOpenstackException);
    assertTrue("ContextError".equals(me2.getContext()));
    assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
    OpenStackResponse openStackResponse = Mockito.mock(OpenStackResponse.class);
    NeutronError explanation = mapper.readValue(new File(RESOURCE_PATH + "NeutronError.json"), NeutronError.class);
    doReturn(explanation).when(openStackResponse).getErrorEntity(eq(NeutronError.class));
    openStackResponseException = new OpenStackResponseException("response", 501, openStackResponse);
    MsoException me3 = commonUtils.neutronExceptionToMsoException(openStackResponseException, "ContextError");
    assertTrue(me3 instanceof MsoOpenstackException);
    assertEquals("501 type: message", me3.toString());
}
Also used : OpenStackResponse(com.woorea.openstack.base.client.OpenStackResponse) MsoException(org.onap.so.openstack.exceptions.MsoException) NeutronError(com.woorea.openstack.quantum.model.NeutronError) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) MsoIOException(org.onap.so.openstack.exceptions.MsoIOException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) File(java.io.File) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Aggregations

OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)2 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)2 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)2 NeutronError (com.woorea.openstack.quantum.model.NeutronError)2 MsoException (org.onap.so.openstack.exceptions.MsoException)2 MsoIOException (org.onap.so.openstack.exceptions.MsoIOException)2 MsoOpenstackException (org.onap.so.openstack.exceptions.MsoOpenstackException)2 OpenStackResponse (com.woorea.openstack.base.client.OpenStackResponse)1 File (java.io.File)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 BaseTest (org.onap.so.BaseTest)1 ServiceEndpointNotFoundException (org.onap.so.cloud.authentication.ServiceEndpointNotFoundException)1 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)1