Search in sources :

Example 46 with MsoException

use of org.onap.so.openstack.exceptions.MsoException 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)

Example 47 with MsoException

use of org.onap.so.openstack.exceptions.MsoException in project so by onap.

the class MsoCommonUtilsTest method testHeatExceptionToMsoException.

@Test
public final void testHeatExceptionToMsoException() throws JsonParseException, JsonMappingException, IOException {
    OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
    OpenStackBaseException openStackResponseException = new OpenStackResponseException("response", 1);
    MsoException me = commonUtils.heatExceptionToMsoException(openStackConnectException, "ContextError");
    assertTrue(me instanceof MsoIOException);
    assertTrue("connect".equals(me.getMessage()));
    MsoException me2 = commonUtils.heatExceptionToMsoException(openStackResponseException, "ContextError");
    assertTrue(me2 instanceof MsoOpenstackException);
    assertTrue("ContextError".equals(me2.getContext()));
    assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
    OpenStackResponse openStackResponse = Mockito.mock(OpenStackResponse.class);
    Explanation explanation = mapper.readValue(new File(RESOURCE_PATH + "Explanation.json"), Explanation.class);
    doReturn(explanation).when(openStackResponse).getErrorEntity(eq(Explanation.class));
    openStackResponseException = new OpenStackResponseException("response", 501, openStackResponse);
    MsoException me3 = commonUtils.heatExceptionToMsoException(openStackResponseException, "ContextError");
    assertTrue(me3 instanceof MsoOpenstackException);
    assertEquals("1 title: explanation, error.type=null, error.message=null", me3.toString());
}
Also used : OpenStackResponse(com.woorea.openstack.base.client.OpenStackResponse) MsoException(org.onap.so.openstack.exceptions.MsoException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) Explanation(com.woorea.openstack.heat.model.Explanation) 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)

Example 48 with MsoException

use of org.onap.so.openstack.exceptions.MsoException in project so by onap.

the class NovaClientImpl method queryFlavorById.

/**
 * Query Networks
 *
 * @param cloudSiteId the cloud site id
 * @param tenantId the tenant id
 * @param id of the network
 * @return the the flavor from openstack
 * @throws MsoCloudSiteNotFound the mso cloud site not found
 * @throws NeutronClientException if the client cannot be built this is thrown
 */
public Flavor queryFlavorById(String cloudSiteId, String tenantId, String id) throws MsoCloudSiteNotFound, NovaClientException {
    try {
        Nova novaClient = client.getNovaClient(cloudSiteId, tenantId);
        OpenStackRequest<Flavor> request = novaClient.flavors().show(id);
        return executeAndRecordOpenstackRequest(request, false);
    } catch (MsoException e) {
        logger.error("Error building Nova Client", e);
        throw new NovaClientException("Error building Nova Client", e);
    }
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) Nova(com.woorea.openstack.nova.Nova) Flavor(com.woorea.openstack.nova.model.Flavor)

Example 49 with MsoException

use of org.onap.so.openstack.exceptions.MsoException in project so by onap.

the class NovaClientImpl method queryServerById.

public Server queryServerById(String cloudSiteId, String tenantId, String id) throws NovaClientException {
    try {
        Nova novaClient = client.getNovaClient(cloudSiteId, tenantId);
        OpenStackRequest<Server> request = novaClient.servers().show(id);
        return executeAndRecordOpenstackRequest(request, false);
    } catch (MsoException e) {
        logger.error("Error building Nova Client", e);
        throw new NovaClientException("Error building Nova Client", e);
    }
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) Server(com.woorea.openstack.nova.model.Server) Nova(com.woorea.openstack.nova.Nova)

Example 50 with MsoException

use of org.onap.so.openstack.exceptions.MsoException in project so by onap.

the class NovaClientImpl method attachVolume.

public void attachVolume(String cloudSiteId, String tenantId, String serverId, VolumeAttachment volumeAttachment) throws NovaClientException {
    Nova novaClient;
    try {
        novaClient = client.getNovaClient(cloudSiteId, tenantId);
        OpenStackRequest<Void> request = novaClient.servers().attachVolume(serverId, volumeAttachment.getVolumeId(), volumeAttachment.getDevice());
        executeAndRecordOpenstackRequest(request, false);
    } catch (MsoException e) {
        logger.error("Error building Nova Client", e);
        throw new NovaClientException("Error building Nova Client", e);
    }
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) Nova(com.woorea.openstack.nova.Nova)

Aggregations

MsoException (org.onap.so.openstack.exceptions.MsoException)53 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)12 CloudSite (org.onap.so.db.catalog.beans.CloudSite)12 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)12 Nova (com.woorea.openstack.nova.Nova)10 StackInfo (org.onap.so.openstack.beans.StackInfo)10 Quantum (com.woorea.openstack.quantum.Quantum)9 MsoOpenstackException (org.onap.so.openstack.exceptions.MsoOpenstackException)9 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)8 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)8 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 BaseTest (org.onap.so.BaseTest)7 MsoIOException (org.onap.so.openstack.exceptions.MsoIOException)7 HashMap (java.util.HashMap)6 VnfException (org.onap.so.adapters.vnf.exceptions.VnfException)6 MsoCloudSiteNotFound (org.onap.so.openstack.exceptions.MsoCloudSiteNotFound)6 IOException (java.io.IOException)5 NetworkException (org.onap.so.adapters.network.exceptions.NetworkException)5 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)5