diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src')
2 files changed, 27 insertions, 8 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index ccdcf92953..1fabcb279c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -71,6 +71,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ public static final String VNF_ID = "vnf_id"; public static final String VF_MODULE_ID = "vf_module_id"; public static final String TEMPLATE_TYPE = "template_type"; + public static final String MULTICLOUD_QUERY_BODY_NULL = "multicloudQueryBody is null"; public static final List<String> MULTICLOUD_INPUTS = Arrays.asList(OOF_DIRECTIVES, SDNC_DIRECTIVES, USER_DIRECTIVES, TEMPLATE_TYPE); @@ -302,11 +303,16 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase()); } else if (response.getStatus() == Response.Status.OK.getStatusCode() && response.hasEntity()) { multicloudQueryBody = getQueryBody((java.io.InputStream)response.getEntity()); - returnInfo.setCanonicalName(stackName + "/" + multicloudQueryBody.getWorkloadId()); - returnInfo.setStatus(getHeatStatus(multicloudQueryBody.getWorkloadStatus())); - returnInfo.setStatusMessage(multicloudQueryBody.getWorkloadStatus()); - if (logger.isDebugEnabled()) { - logger.debug("Multicloud Create Response Body: " + multicloudQueryBody.toString()); + if (multicloudQueryBody != null) { + returnInfo.setCanonicalName(stackName + "/" + multicloudQueryBody.getWorkloadId()); + returnInfo.setStatus(getHeatStatus(multicloudQueryBody.getWorkloadStatus())); + returnInfo.setStatusMessage(multicloudQueryBody.getWorkloadStatus()); + if (logger.isDebugEnabled()) { + logger.debug("Multicloud Create Response Body: " + multicloudQueryBody.toString()); + } + } else { + returnInfo.setStatus(HeatStatus.FAILED); + returnInfo.setStatusMessage(MULTICLOUD_QUERY_BODY_NULL); } } else { returnInfo.setStatus(HeatStatus.FAILED); @@ -624,7 +630,9 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ } private HeatStatus mapResponseToHeatStatus(Response response) { - if (response.getStatusInfo().getStatusCode() == Response.Status.OK.getStatusCode()) { + if (response == null) { + return HeatStatus.FAILED; + } else if (response.getStatusInfo().getStatusCode() == Response.Status.OK.getStatusCode()) { return HeatStatus.CREATED; } else if (response.getStatusInfo().getStatusCode() == Response.Status.CREATED.getStatusCode()) { return HeatStatus.CREATED; diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java index 669e47f94d..e066c4eec6 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java @@ -4,8 +4,6 @@ * ================================================================================ * Copyright (C) 2019 Samsung Intellectual Property. All rights reserved. * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,6 +29,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.when; +import static org.onap.so.openstack.utils.MsoMulticloudUtils.MULTICLOUD_QUERY_BODY_NULL; import java.io.IOException; import java.util.HashMap; @@ -123,6 +122,18 @@ public class MsoMulticloudUtilsTest extends BaseTest { assertTrue(HeatStatus.NOTFOUND == result.getStatus()); } + @Test + public void queryStackWithNullMulticloudQueryBody() throws MsoException { + wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/instanceId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(CREATE_STACK_RESPONSE) + .withStatus(HttpStatus.SC_OK))); + + StackInfo result = multicloudUtils.queryStack("MTN13", "CloudOwner", "TEST-tenant", "instanceId"); + assertTrue(HeatStatus.FAILED == result.getStatus()); + assertEquals(MULTICLOUD_QUERY_BODY_NULL, result.getStatusMessage()); + } + @Test(expected = VduException.class) public void updateVdu() throws MsoException { multicloudUtils.updateVdu(new CloudInfo(), "instanceId", new HashMap<>(), new VduModelInfo(), |