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());
}
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());
}
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);
}
}
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);
}
}
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);
}
}
Aggregations