aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
authorEric Multanen <eric.w.multanen@intel.com>2019-04-05 23:13:24 -0700
committerEric Multanen <eric.w.multanen@intel.com>2019-04-05 23:21:39 -0700
commitdba65feceeaa8c8d73479a088e735ea0fe890d8c (patch)
tree7ec64f37e8c1c552d61aeea737fc423288756bfb /adapters
parent0fee038584a0e66db618d24eada8ba6e0da05001 (diff)
Allow volume groups in multicloud plugin adapter
Remove multicloud logic that was skipping over volume group and non-base module requests. Change-Id: Ie121fec2ab752b4d974a1757d01317cd6feef30d Issue-ID: SO-1445 Signed-off-by: Eric Multanen <eric.w.multanen@intel.com>
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java69
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java94
2 files changed, 109 insertions, 54 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java
index 584c934843..82b194a973 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java
@@ -705,18 +705,16 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter {
throw new VnfException("Exception during create VF " + e.getMessage());
}
- // Perform a version check against cloudSite
+ // Perform a version check against cloudSite
// Obtain the cloud site information where we will create the VF Module
- Boolean usingMulticloud = false;
Optional<CloudSite> cloudSiteOp = cloudConfig.getCloudSite (cloudSiteId);
if (!cloudSiteOp.isPresent()) {
// If cloudSiteId is not present in the catalog DB, then default to multicloud
- usingMulticloud = true;
+ logger.debug("{} is not present in cloud_site catalog DB, defaulting to Multicloud plugin adapter", cloudSiteId);
} else {
CloudSite cloudSite = cloudSiteOp.get();
MavenLikeVersioning aicV = new MavenLikeVersioning();
aicV.setVersion(cloudSite.getCloudVersion());
- usingMulticloud = getUsingMulticloud(cloudSite);
String vnfMin = vnfResource.getAicVersionMin();
String vnfMax = vnfResource.getAicVersionMax();
@@ -743,24 +741,20 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter {
// Use the VduPlugin.
VduPlugin vduPlugin = getVduPlugin(cloudSiteId, cloudOwner);
- // First, look up to see if the VF already exists, unless using multicloud adapter
-
long subStartTime1 = System.currentTimeMillis ();
- if (!usingMulticloud) {
- try {
- vduInstance = vduPlugin.queryVdu (cloudInfo, vfModuleName);
- }
- catch (VduException me) {
- // Failed to query the VDU due to a plugin exception.
- String error = "Create VF Module: Query " + vfModuleName + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + me ;
- logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_QUERY_VNF_ERR.toString(), vfModuleName,
- cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu", ErrorCode.DataError.getValue(),
- "Exception - queryVdu", me);
- logger.debug(error);
- // Convert to a generic VnfException
- me.addContext ("CreateVFModule");
- throw new VnfException (me);
- }
+ try {
+ vduInstance = vduPlugin.queryVdu (cloudInfo, vfModuleName);
+ }
+ catch (VduException me) {
+ // Failed to query the VDU due to a plugin exception.
+ String error = "Create VF Module: Query " + vfModuleName + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + me ;
+ logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_QUERY_VNF_ERR.toString(), vfModuleName,
+ cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu", ErrorCode.DataError.getValue(),
+ "Exception - queryVdu", me);
+ logger.debug(error);
+ // Convert to a generic VnfException
+ me.addContext ("CreateVFModule");
+ throw new VnfException (me);
}
// More precise handling/messaging if the Module already exists
@@ -838,7 +832,7 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter {
Map<String, Object> volumeGroupOutputs = null;
// If a Volume Group was provided, query its outputs for inclusion in Module input parameters
- if (!usingMulticloud && volumeGroupId != null) {
+ if (volumeGroupId != null) {
long subStartTime2 = System.currentTimeMillis ();
VduInstance volumeVdu = null;
try {
@@ -887,8 +881,7 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter {
logger.debug("WARNING: Add-on Module request - no Base Module ID provided");
}
- // Need to verify if multicloud needs to have the vaseVfModuleId passed to it. Ignoring this for now.
- if (!usingMulticloud && baseVfModuleId != null) {
+ if (baseVfModuleId != null) {
long subStartTime2 = System.currentTimeMillis ();
VduInstance baseVdu = null;
try {
@@ -942,15 +935,15 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter {
}
if (heatTemplate == null) {
- String error = "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType + ", reqType="
- + requestType;
- logger.error("{} {} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Template ID", vfModuleType,
- "VNF", ErrorCode.DataError.getValue(), error);
- logger.debug(error);
- throw new VnfException(error, MsoExceptionCategory.INTERNAL);
- } else {
- logger.debug("Got HEAT Template from DB: " + heatTemplate.getHeatTemplate());
- }
+ String error = "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType + ", reqType="
+ + requestType;
+ logger.error("{} {} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Template ID", vfModuleType,
+ "VNF", ErrorCode.DataError.getValue(), error);
+ logger.debug(error);
+ throw new VnfException(error, MsoExceptionCategory.INTERNAL);
+ } else {
+ logger.debug("Got HEAT Template from DB: " + heatTemplate.getHeatTemplate());
+ }
if (heatEnvironment == null) {
String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType;
@@ -1011,12 +1004,10 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter {
if (!extraInputs.isEmpty()) {
// Add multicloud inputs
- boolean multicloudInputs = false;
for (String key : MsoMulticloudUtils.MULTICLOUD_INPUTS) {
if (extraInputs.contains(key)) {
goldenInputs.put(key, inputs.get(key));
extraInputs.remove(key);
- multicloudInputs = true;
if (extraInputs.isEmpty()) {
break;
}
@@ -1275,12 +1266,4 @@ public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter {
// Default if no cloudSite record exists - return multicloud plugin
return multicloudUtils;
}
-
- private Boolean getUsingMulticloud (CloudSite cloudSite) {
- if (cloudSite.getOrchestrator().equalsIgnoreCase("MULTICLOUD")) {
- return true;
- } else {
- return false;
- }
- }
}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java
index f3ad4e6d7d..507251bb80 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java
@@ -25,6 +25,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.delete;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
@@ -36,8 +39,12 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onap.so.adapters.vdu.VduModelInfo;
+import org.onap.so.adapters.vnf.exceptions.VnfException;
import org.onap.so.cloud.CloudConfig;
import org.onap.so.entity.MsoRequest;
+import org.onap.so.openstack.beans.StackInfo;
+import org.onap.so.openstack.exceptions.MsoException;
import org.springframework.beans.factory.annotation.Autowired;
public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{
@@ -50,6 +57,20 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{
@Autowired
private CloudConfig cloudConfig;
+ private static final String CREATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": "
+ + "\"workload-id\", \"template_response\": {\"stack\": {\"id\": \"TEST-stack\", \"links\": []}}}";
+ private static final String UPDATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": "
+ + "\"workload-id\"}";
+ private static final String GET_CREATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": "
+ + "\"workload-id\", \"workload_status\": \"CREATE_COMPLETE\"}";
+ private static final String GET_UPDATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": "
+ + "\"workload-id\", \"workload_status\": \"UPDATE_COMPLETE\"}";
+
+ private static final String MULTICLOUD_CREATE_PATH = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload";
+ private static final String MULTICLOUD_UPDATE_PATH = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id";
+ private static final String MULTICLOUD_GET_PATH_BY_NAME = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname";
+ private static final String MULTICLOUD_GET_PATH_BY_ID = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id";
+
@Before
public void before() throws Exception {
super.orchestrator = "multicloud";
@@ -59,10 +80,11 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{
@Test
public void createVfModule() throws Exception {
-
+
Map<String, Object> stackInputs = new HashMap<>();
stackInputs.put("oof_directives", "{}");
stackInputs.put("sdnc_directives", "{}");
+ stackInputs.put("user_directives", "{}");
stackInputs.put("generic_vnf_id", "genVNFID");
stackInputs.put("vf_module_id", "vfMODULEID");
@@ -70,23 +92,73 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{
msoRequest.setRequestId("12345");
msoRequest.setServiceInstanceId("12345");
- wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname")).willReturn(aResponse()
- //.withHeader()
+ wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_NAME))
+ .willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
.withStatus(HttpStatus.SC_NOT_FOUND)));
- wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")).willReturn(aResponse()
- //.withHeader()
- .withBodyFile("MulticloudResponse_Stack.json")
+ wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID))
+ .inScenario("CREATE").whenScenarioStateIs("CREATING")
+ .willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBody(GET_CREATE_STACK_RESPONSE)
.withStatus(HttpStatus.SC_OK)));
- wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname/outputs")).willReturn(aResponse()
- .withStatus(HttpStatus.SC_NOT_FOUND)));
+ wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID))
+ .inScenario("CREATE").whenScenarioStateIs("UPDATING")
+ .willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBody(GET_UPDATE_STACK_RESPONSE)
+ .withStatus(HttpStatus.SC_OK)));
- wireMockServer.stubFor(post(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload")).willReturn(aResponse()
+ wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).inScenario("CREATE")
+ .willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
.withBodyFile("MulticloudResponse_Stack_Create.json")
- .withStatus(HttpStatus.SC_CREATED)));
+ .withStatus(HttpStatus.SC_CREATED))
+ .willSetStateTo("CREATING"));
+
+ wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_UPDATE_PATH)).inScenario("CREATE")
+ .willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBody(UPDATE_STACK_RESPONSE)
+ .withStatus(HttpStatus.SC_ACCEPTED))
+ .willSetStateTo("UPDATING"));
+
+ try {
+ instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ } catch (VnfException e) {
+ fail("createVfModule success expected, failed with exception: " + e.toString());
+ }
+ wireMockServer.resetScenarios();
+ }
+
+ @Test
+ public void createVfModuleAlreadyExists() throws Exception {
+
+ Map<String, Object> stackInputs = new HashMap<>();
+ stackInputs.put("oof_directives", "{}");
+ stackInputs.put("sdnc_directives", "{}");
+ stackInputs.put("user_directives", "{}");
+ stackInputs.put("generic_vnf_id", "genVNFID");
+ stackInputs.put("vf_module_id", "vfMODULEID");
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname")).willReturn(aResponse()
+ //.withHeader()
+ .withBodyFile("MulticloudResponse_Stack.json")
+ .withStatus(HttpStatus.SC_OK)));
- instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ try {
+ instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ } catch (VnfException e) {
+ assertTrue(e.toString().contains("Resource vfname already exists in owner/cloud/tenant CloudOwner/MTN13/123 with ID vfname/vfname"));
+ return;
+ }
+ fail("VnfAlreadyExists Exception expected!");
}
@Test