summaryrefslogtreecommitdiffstats
path: root/adapters/mso-vnf-adapter
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-03-14 09:22:15 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-14 09:22:15 +0000
commit09f3630ea990197e9d7b669aa2d6a63ec397bf3e (patch)
tree6625d3e9ac31600d86bf54a50e75dba61cc2c82a /adapters/mso-vnf-adapter
parenta56de0e221751debd038aca5b6d20d8f9325d294 (diff)
parent38f720752af4d4aad8c4e467a288d9048659f688 (diff)
Merge "AT&T 1712 and 1802 release code"
Diffstat (limited to 'adapters/mso-vnf-adapter')
-rw-r--r--adapters/mso-vnf-adapter/WebContent/WEB-INF/web.xml7
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterAsyncImpl.java51
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java1062
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfCloudifyAdapterImpl.java1256
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRest.java2
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestUtils.java85
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestV2.java629
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VolumeAdapterRestV2.java578
-rwxr-xr-xadapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java2
-rwxr-xr-xadapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java2
-rwxr-xr-xadapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java2
-rwxr-xr-xadapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java2
-rw-r--r--adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java25
-rw-r--r--adapters/mso-vnf-adapter/src/test/resources/cloud_config.json94
-rw-r--r--adapters/mso-vnf-adapter/src/test/resources/mso.properties27
15 files changed, 3228 insertions, 596 deletions
diff --git a/adapters/mso-vnf-adapter/WebContent/WEB-INF/web.xml b/adapters/mso-vnf-adapter/WebContent/WEB-INF/web.xml
index e69486e1fd..a2e6c0c517 100644
--- a/adapters/mso-vnf-adapter/WebContent/WEB-INF/web.xml
+++ b/adapters/mso-vnf-adapter/WebContent/WEB-INF/web.xml
@@ -26,10 +26,15 @@
org.openecomp.mso.logger.MsoLoggingServlet,
org.openecomp.mso.adapters.vnf.HealthCheckHandler,
org.openecomp.mso.adapters.vnf.VnfAdapterRest,
+ org.openecomp.mso.adapters.vnf.VnfAdapterRestV2,
org.openecomp.mso.adapters.vnf.VolumeAdapterRest
</param-value>
</context-param>
<context-param>
+ <param-name>resteasy.providers</param-name>
+ <param-value>org.openecomp.mso.adapters.providers.JettisonStyleMapperProvider</param-value>
+ </context-param>
+ <context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
@@ -46,7 +51,7 @@
<web-resource-collection>
<web-resource-name>RestRequests</web-resource-name>
<description>Rest Ingress Requests</description>
- <url-pattern>/rest/v1/*</url-pattern>
+ <url-pattern>/rest/v*/*</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
<http-method>PUT</http-method>
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterAsyncImpl.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterAsyncImpl.java
index 5c654298fb..df04d1d2ad 100644
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterAsyncImpl.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterAsyncImpl.java
@@ -54,10 +54,11 @@ import org.openecomp.mso.properties.MsoPropertiesFactory;
@WebService(serviceName = "VnfAdapterAsync", endpointInterface = "org.openecomp.mso.adapters.vnf.MsoVnfAdapterAsync", targetNamespace = "http://org.openecomp.mso/vnfA")
public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
- MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
- CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
+ MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
- public static final String MSO_PROP_VNF_ADAPTER="MSO_PROP_VNF_ADAPTER";
+ CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
+
+ public static final String MSO_PROP_VNF_ADAPTER="MSO_PROP_VNF_ADAPTER";
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
private static final String BPEL_AUTH_PROP = "org.openecomp.mso.adapters.vnf.bpelauth";
@@ -154,8 +155,8 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
vnfRollback);
MsoLogger.setServiceName (serviceName);
} catch (VnfException e) {
- MsoLogger.setServiceName (serviceName);
- LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vnfName, cloudSiteId, tenantId, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "VnfException in createVnfA", e);
+ MsoLogger.setServiceName (serviceName);
+ LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vnfName, cloudSiteId, tenantId, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "VnfException in createVnfA", e);
org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
String eMsg = null;
try {
@@ -228,8 +229,8 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
vnfAdapter.updateVnf (cloudSiteId, tenantId, vnfType,vnfVersion, vnfName, requestType, volumeGroupHeatStackId, inputs, msoRequest, outputs, vnfRollback);
MsoLogger.setServiceName (serviceName);
} catch (VnfException e) {
- MsoLogger.setServiceName (serviceName);
- LOGGER.error (MessageEnum.RA_UPDATE_VNF_ERR, vnfName, cloudSiteId, tenantId, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e);
+ MsoLogger.setServiceName (serviceName);
+ LOGGER.error (MessageEnum.RA_UPDATE_VNF_ERR, vnfName, cloudSiteId, tenantId, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e);
org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
String eMsg = null;
try {
@@ -238,7 +239,7 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
.getCategory ()
.name ());
} catch (Exception e1) {
- LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
+ LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
}
// Build and send Asynchronous error response
try {
@@ -310,7 +311,7 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
vnfAdapter.queryVnf (cloudSiteId, tenantId, vnfName, msoRequest, vnfExists, vnfId, status, outputs);
MsoLogger.setServiceName (serviceName);
} catch (VnfException e) {
- MsoLogger.setServiceName (serviceName);
+ MsoLogger.setServiceName (serviceName);
LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnfA notification", e);
org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
String eMsg = null;
@@ -320,7 +321,7 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
.getCategory ()
.name ());
} catch (Exception e1) {
- LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
+ LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
}
// Build and send Asynchronous error response
try {
@@ -395,8 +396,8 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
vnfAdapter.deleteVnf (cloudSiteId, tenantId, vnfName, msoRequest);
MsoLogger.setServiceName (serviceName);
} catch (VnfException e) {
- MsoLogger.setServiceName (serviceName);
- LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vnfName, cloudSiteId, tenantId, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e);
+ MsoLogger.setServiceName (serviceName);
+ LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vnfName, cloudSiteId, tenantId, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e);
org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
String eMsg = null;
try {
@@ -405,7 +406,7 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
.getCategory ()
.name ());
} catch (Exception e1) {
- LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
+ LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
}
// Build and send Asynchronous error response
try {
@@ -465,8 +466,8 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
vnfAdapter.rollbackVnf (rollback);
MsoLogger.setServiceName (serviceName);
} catch (VnfException e) {
- MsoLogger.setServiceName (serviceName);
- LOGGER.error (MessageEnum.RA_ROLLBACK_VNF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e);
+ MsoLogger.setServiceName (serviceName);
+ LOGGER.error (MessageEnum.RA_ROLLBACK_VNF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e);
org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
String eMsg = null;
try {
@@ -475,7 +476,7 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
.getCategory ()
.name ());
} catch (Exception e1) {
- LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
+ LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
}
// Build and send Asynchronous error response
try {
@@ -513,11 +514,11 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
cvrb.setCloudSiteId (hVrb.value.getCloudSiteId ());
if (hVrb.value.getMsoRequest() != null) {
- cmr.setRequestId (hVrb.value.getMsoRequest ().getRequestId ());
- cmr.setServiceInstanceId (hVrb.value.getMsoRequest ().getServiceInstanceId ());
+ cmr.setRequestId (hVrb.value.getMsoRequest ().getRequestId ());
+ cmr.setServiceInstanceId (hVrb.value.getMsoRequest ().getServiceInstanceId ());
} else {
- cmr.setRequestId (null);
- cmr.setServiceInstanceId (null);
+ cmr.setRequestId (null);
+ cmr.setServiceInstanceId (null);
}
cvrb.setMsoRequest (cmr);
cvrb.setVnfId (hVrb.value.getVnfId ());
@@ -556,8 +557,8 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
UpdateVnfNotification.Outputs.Entry entry = new UpdateVnfNotification.Outputs.Entry ();
for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
- String key = mapEntry.getKey();
- String value = mapEntry.getValue();
+ String key = mapEntry.getKey();
+ String value = mapEntry.getValue();
entry.setKey (key);
entry.setValue (value);
outputs.getEntry ().add (entry);
@@ -577,8 +578,8 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
QueryVnfNotification.Outputs.Entry entry = new QueryVnfNotification.Outputs.Entry ();
for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
- String key = mapEntry.getKey();
- String value = mapEntry.getValue();
+ String key = mapEntry.getKey();
+ String value = mapEntry.getValue();
entry.setKey (key);
entry.setValue (value);
outputs.getEntry ().add (entry);
@@ -596,7 +597,7 @@ public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - WSDL not found", e);
}
if (warWsdlLoc == null) {
- LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "WSDL not found");
+ LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "WSDL not found");
} else {
try {
LOGGER.debug ("VnfAdpaterNotify.wsdl location:" + warWsdlLoc.toURI ().toString ());
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
index 9022c26ccd..1db4c9f77a 100644
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
@@ -21,10 +21,23 @@
package org.openecomp.mso.adapters.vnf;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.ObjectMapper;
+import java.util.Scanner;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.jws.WebService;
+import javax.xml.ws.Holder;
+
import org.openecomp.mso.adapters.vnf.exceptions.VnfAlreadyExists;
import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
import org.openecomp.mso.adapters.vnf.exceptions.VnfNotFound;
@@ -55,26 +68,19 @@ import org.openecomp.mso.openstack.utils.MsoHeatUtils;
import org.openecomp.mso.openstack.utils.MsoHeatUtilsWithUpdate;
import org.openecomp.mso.properties.MsoPropertiesFactory;
-import javax.jws.WebService;
-import javax.xml.ws.Holder;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
@WebService(serviceName = "VnfAdapter", endpointInterface = "org.openecomp.mso.adapters.vnf.MsoVnfAdapter", targetNamespace = "http://org.openecomp.mso/vnf")
public class MsoVnfAdapterImpl implements MsoVnfAdapter {
- CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
- protected CloudConfig cloudConfig = null;
+ CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
+ protected CloudConfig cloudConfig = null;
- MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory();
+ MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory();
- private static final String MSO_PROP_VNF_ADAPTER = "MSO_PROP_VNF_ADAPTER";
+ private static final String MSO_PROP_VNF_ADAPTER = "MSO_PROP_VNF_ADAPTER";
private static final String MSO_CONFIGURATION_ERROR = "MsoConfigurationError";
private static final String VNF_ADAPTER_SERVICE_NAME = "MSO-BPMN:MSO-VnfAdapter.";
private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
@@ -96,8 +102,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
* @param msoPropFactory
*/
public MsoVnfAdapterImpl(MsoPropertiesFactory msoPropFactory, CloudConfigFactory cloudConfigFact) {
- this.msoPropertiesFactory = msoPropFactory;
- this.cloudConfigFactory = cloudConfigFact;
+ this.msoPropertiesFactory = msoPropFactory;
+ this.cloudConfigFactory = cloudConfigFact;
}
/**
@@ -160,65 +166,65 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
Holder <String> vnfId,
Holder <Map <String, String>> outputs,
Holder <VnfRollback> rollback) throws VnfException {
- // Create a hook here to catch shortcut createVf requests:
- if (requestType != null) {
- if (requestType.startsWith("VFMOD")) {
- LOGGER.debug("Calling createVfModule from createVnf -- requestType=" + requestType);
- String newRequestType = requestType.substring(5);
- String vfVolGroupHeatStackId = "";
- String vfBaseHeatStackId = "";
- try {
- if (volumeGroupHeatStackId != null) {
- vfVolGroupHeatStackId = volumeGroupHeatStackId.substring(0, volumeGroupHeatStackId.lastIndexOf("|"));
- vfBaseHeatStackId = volumeGroupHeatStackId.substring(volumeGroupHeatStackId.lastIndexOf("|")+1);
- }
- } catch (Exception e) {
- // might be ok - both are just blank
- LOGGER.debug("ERROR trying to parse the volumeGroupHeatStackId " + volumeGroupHeatStackId,e);
- }
- this.createVfModule(cloudSiteId,
- tenantId,
- vnfType,
- vnfVersion,
- vnfName,
- newRequestType,
- vfVolGroupHeatStackId,
- vfBaseHeatStackId,
+ // Create a hook here to catch shortcut createVf requests:
+ if (requestType != null) {
+ if (requestType.startsWith("VFMOD")) {
+ LOGGER.debug("Calling createVfModule from createVnf -- requestType=" + requestType);
+ String newRequestType = requestType.substring(5);
+ String vfVolGroupHeatStackId = "";
+ String vfBaseHeatStackId = "";
+ try {
+ if (volumeGroupHeatStackId != null) {
+ vfVolGroupHeatStackId = volumeGroupHeatStackId.substring(0, volumeGroupHeatStackId.lastIndexOf("|"));
+ vfBaseHeatStackId = volumeGroupHeatStackId.substring(volumeGroupHeatStackId.lastIndexOf("|")+1);
+ }
+ } catch (Exception e) {
+ // might be ok - both are just blank
+ LOGGER.debug("ERROR trying to parse the volumeGroupHeatStackId " + volumeGroupHeatStackId,e);
+ }
+ this.createVfModule(cloudSiteId,
+ tenantId,
+ vnfType,
+ vnfVersion,
+ vnfName,
+ newRequestType,
+ vfVolGroupHeatStackId,
+ vfBaseHeatStackId,
null,
- inputs,
- failIfExists,
- backout,
- msoRequest,
- vnfId,
- outputs,
- rollback);
- return;
- }
- }
- // createVf will know if the requestType starts with "X" that it's the "old" way
- StringBuilder newRequestTypeSb = new StringBuilder("X");
- String vfVolGroupHeatStackId = "";
- String vfBaseHeatStackId = "";
- if (requestType != null) {
- newRequestTypeSb.append(requestType);
- }
- this.createVfModule(cloudSiteId,
+ inputs,
+ failIfExists,
+ backout,
+ msoRequest,
+ vnfId,
+ outputs,
+ rollback);
+ return;
+ }
+ }
+ // createVf will know if the requestType starts with "X" that it's the "old" way
+ StringBuilder newRequestTypeSb = new StringBuilder("X");
+ String vfVolGroupHeatStackId = "";
+ String vfBaseHeatStackId = "";
+ if (requestType != null) {
+ newRequestTypeSb.append(requestType);
+ }
+ this.createVfModule(cloudSiteId,
tenantId,
- vnfType,
- vnfVersion,
+ vnfType,
+ vnfVersion,
vnfName,
- newRequestTypeSb.toString(),
- vfVolGroupHeatStackId,
- vfBaseHeatStackId,
- null,
- inputs,
- failIfExists,
- backout,
- msoRequest,
- vnfId,
- outputs,
- rollback);
- // End createVf shortcut
+ newRequestTypeSb.toString(),
+ vfVolGroupHeatStackId,
+ vfBaseHeatStackId,
+ null,
+ inputs,
+ failIfExists,
+ backout,
+ msoRequest,
+ vnfId,
+ outputs,
+ rollback);
+ // End createVf shortcut
}
@Override
@@ -233,10 +239,10 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
MsoRequest msoRequest,
Holder <Map <String, String>> outputs,
Holder <VnfRollback> rollback) throws VnfException {
- // As of 1707 - this method should no longer be called
- MsoLogger.setLogContext (msoRequest.getRequestId (), msoRequest.getServiceInstanceId ());
- MsoLogger.setServiceName ("UpdateVnf");
- LOGGER.debug("UpdateVnf called?? This should not be called any longer - update vfModule");
+ // As of 1707 - this method should no longer be called
+ MsoLogger.setLogContext (msoRequest.getRequestId (), msoRequest.getServiceInstanceId ());
+ MsoLogger.setServiceName ("UpdateVnf");
+ LOGGER.debug("UpdateVnf called?? This should not be called any longer - update vfModule");
}
/**
@@ -264,7 +270,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
Holder <VnfStatus> status,
Holder <Map <String, String>> outputs) throws VnfException {
MsoLogger.setLogContext (msoRequest);
- MsoLogger.setServiceName ("QueryVnf");
+ MsoLogger.setServiceName ("QueryVnf");
LOGGER.debug ("Querying VNF " + vnfName + " in " + cloudSiteId + "/" + tenantId);
// Will capture execution time for metrics
@@ -326,7 +332,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
String vnfName,
MsoRequest msoRequest) throws VnfException {
MsoLogger.setLogContext (msoRequest);
- MsoLogger.setServiceName ("DeleteVnf");
+ MsoLogger.setServiceName ("DeleteVnf");
LOGGER.debug ("Deleting VNF " + vnfName + " in " + cloudSiteId + "/" + tenantId);
// Will capture execution time for metrics
long startTime = System.currentTimeMillis ();
@@ -366,7 +372,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
public void rollbackVnf (VnfRollback rollback) throws VnfException {
long startTime = System.currentTimeMillis ();
MsoLogger.setServiceName ("RollbackVnf");
- // rollback may be null (e.g. if stack already existed when Create was called)
+ // rollback may be null (e.g. if stack already existed when Create was called)
if (rollback == null) {
LOGGER.info (MessageEnum.RA_ROLLBACK_NULL, "OpenStack", "rollbackVnf");
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Rollback request content is null");
@@ -426,33 +432,35 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
if (value instanceof String) {
stringOutputs.put (key, (String) value);
} else if (value instanceof Integer) {
- try {
- String str = "" + value;
- stringOutputs.put(key, str);
- } catch (Exception e) {
- LOGGER.debug("Unable to add " + key + " to outputs",e);
- }
+ try {
+ String str = "" + value;
+ stringOutputs.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("Unable to add " + key + " to outputs",e);
+ }
} else if (value instanceof JsonNode) {
- try {
- String str = this.convertNode((JsonNode) value);
- stringOutputs.put(key, str);
- } catch (Exception e) {
- LOGGER.debug("Unable to add " + key + " to outputs - exception converting JsonNode",e);
- }
+ try {
+ //String str = this.convertNode((JsonNode) value);
+ String str = value.toString();
+ stringOutputs.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("Unable to add " + key + " to outputs - exception converting JsonNode",e);
+ }
} else if (value instanceof java.util.LinkedHashMap) {
- try {
- String str = JSON_MAPPER.writeValueAsString(value);
- stringOutputs.put(key, str);
- } catch (Exception e) {
- LOGGER.debug("Unable to add " + key + " to outputs - exception converting LinkedHashMap",e);
- }
+ try {
+ //String str = JSON_MAPPER.writeValueAsString(value);
+ String str = value.toString();
+ stringOutputs.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("Unable to add " + key + " to outputs - exception converting LinkedHashMap",e);
+ }
} else {
- try {
- String str = value.toString();
- stringOutputs.put(key, str);
- } catch (Exception e) {
- LOGGER.debug("Unable to add " + key + " to outputs - unable to call .toString() " + e.getMessage(),e);
- }
+ try {
+ String str = value.toString();
+ stringOutputs.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("Unable to add " + key + " to outputs - unable to call .toString() " + e.getMessage(),e);
+ }
}
}
return stringOutputs;
@@ -514,7 +522,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
LOGGER.debug(sb.toString());
}
-
+
private void sendMapToDebug(Map<String, String> inputs) {
int i = 0;
StringBuilder sb = new StringBuilder("inputs:");
@@ -559,7 +567,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
String str = this.convertNode((JsonNode) obj);
stringMap.put(key, str);
} catch (Exception e) {
- LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for JsonNode "+ key,e);
+ LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for JsonNode "+ key,e);
//okay in this instance - only string values (fqdn) are expected to be needed
}
} else if (obj instanceof java.util.LinkedHashMap) {
@@ -568,21 +576,21 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
String str = JSON_MAPPER.writeValueAsString(obj);
stringMap.put(key, str);
} catch (Exception e) {
- LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for LinkedHashMap "+ key,e);
- }
- } else if (obj instanceof Integer) {
- try {
- String str = "" + obj;
- stringMap.put(key, str);
- } catch (Exception e) {
- LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for Integer "+ key,e);
+ LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for LinkedHashMap "+ key,e);
+ }
+ } else if (obj instanceof Integer) {
+ try {
+ String str = "" + obj;
+ stringMap.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for Integer "+ key,e);
}
} else {
try {
- String str = obj.toString();
+ String str = obj.toString();
stringMap.put(key, str);
} catch (Exception e) {
- LOGGER.debug("DANGER WILL ROBINSON: unable to convert value "+ key + " (" + e.getMessage() + ")",e);
+ LOGGER.debug("DANGER WILL ROBINSON: unable to convert value "+ key + " (" + e.getMessage() + ")",e);
}
}
}
@@ -608,9 +616,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
Holder <String> vnfId,
Holder <Map <String, String>> outputs,
Holder <VnfRollback> rollback) throws VnfException {
- String vfModuleName = vnfName;
- String vfModuleType = vnfType;
- String vfVersion = vnfVersion;
+ String vfModuleName = vnfName;
+ String vfModuleType = vnfType;
+ String vfVersion = vnfVersion;
String mcu = modelCustomizationUuid;
boolean useMCUuid = false;
if (mcu != null && !mcu.isEmpty()) {
@@ -623,45 +631,45 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
useMCUuid = true;
}
}
- MsoLogger.setLogContext (msoRequest);
- MsoLogger.setServiceName ("CreateVfModule");
- String requestTypeString = "";
+ MsoLogger.setLogContext (msoRequest);
+ MsoLogger.setServiceName ("CreateVfModule");
+ String requestTypeString = "";
if (requestType != null && !"".equals(requestType)) {
- requestTypeString = requestType;
+ requestTypeString = requestType;
}
String nestedStackId = null;
if (volumeGroupHeatStackId != null && !"".equals(volumeGroupHeatStackId)) {
- if (!"null".equalsIgnoreCase(volumeGroupHeatStackId)) {
- nestedStackId = volumeGroupHeatStackId;
- }
+ if (!"null".equalsIgnoreCase(volumeGroupHeatStackId)) {
+ nestedStackId = volumeGroupHeatStackId;
+ }
}
String nestedBaseStackId = null;
if (baseVfHeatStackId != null && !"".equals(baseVfHeatStackId)) {
- if (!"null".equalsIgnoreCase(baseVfHeatStackId)) {
- nestedBaseStackId = baseVfHeatStackId;
- }
+ if (!"null".equalsIgnoreCase(baseVfHeatStackId)) {
+ nestedBaseStackId = baseVfHeatStackId;
+ }
}
if (inputs == null) {
- // Create an empty set of inputs
- inputs = new HashMap<>();
- LOGGER.debug("inputs == null - setting to empty");
+ // Create an empty set of inputs
+ inputs = new HashMap<>();
+ LOGGER.debug("inputs == null - setting to empty");
} else {
- this.sendMapToDebug(inputs);
+ this.sendMapToDebug(inputs);
}
//This method will also handle doing things the "old" way - i.e., just orchestrate a VNF
boolean oldWay = false;
if (requestTypeString.startsWith("X")) {
- oldWay = true;
- LOGGER.debug("orchestrating a VNF - *NOT* a module!");
- requestTypeString = requestTypeString.substring(1);
+ oldWay = true;
+ LOGGER.debug("orchestrating a VNF - *NOT* a module!");
+ requestTypeString = requestTypeString.substring(1);
}
// 1607 - let's parse out the request type we're being sent
boolean isBaseRequest = false;
boolean isVolumeRequest = false;
if (requestTypeString.startsWith("VOLUME")) {
- isVolumeRequest = true;
+ isVolumeRequest = true;
}
LOGGER.debug("requestTypeString = " + requestTypeString + ", nestedStackId = " + nestedStackId + ", nestedBaseStackId = " + nestedBaseStackId);
@@ -702,44 +710,44 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
// New with 1607 - more precise handling/messaging if the stack already exists
if (heatStack != null && !(heatStack.getStatus () == HeatStatus.NOTFOUND)) {
- // INIT, CREATED, NOTFOUND, FAILED, BUILDING, DELETING, UNKNOWN, UPDATING, UPDATED
- HeatStatus status = heatStack.getStatus();
- if (status == HeatStatus.INIT || status == HeatStatus.BUILDING || status == HeatStatus.DELETING || status == HeatStatus.UPDATING) {
- // fail - it's in progress - return meaningful error
+ // INIT, CREATED, NOTFOUND, FAILED, BUILDING, DELETING, UNKNOWN, UPDATING, UPDATED
+ HeatStatus status = heatStack.getStatus();
+ if (status == HeatStatus.INIT || status == HeatStatus.BUILDING || status == HeatStatus.DELETING || status == HeatStatus.UPDATING) {
+ // fail - it's in progress - return meaningful error
String error = "Create VF: Stack " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; please wait for it to complete, or fix manually.";
LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists");
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ());
- }
- if (status == HeatStatus.FAILED) {
- // fail - it exists and is in a FAILED state
+ }
+ if (status == HeatStatus.FAILED) {
+ // fail - it exists and is in a FAILED state
String error = "Create VF: Stack " + vfModuleName + " already exists and is in FAILED state in " + cloudSiteId + "/" + tenantId + "; requires manual intervention.";
LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists and is in FAILED state");
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ());
- }
- if (status == HeatStatus.UNKNOWN || status == HeatStatus.UPDATED) {
- // fail - it exists and is in a FAILED state
+ }
+ if (status == HeatStatus.UNKNOWN || status == HeatStatus.UPDATED) {
+ // fail - it exists and is in a FAILED state
String error = "Create VF: Stack " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; requires manual intervention.";
LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists and is in UPDATED or UNKNOWN state");
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ());
- }
- if (status == HeatStatus.CREATED) {
- // fail - it exists
- if (failIfExists != null && failIfExists) {
- String error = "Create VF: Stack " + vfModuleName + " already exists in " + cloudSiteId + "/" + tenantId;
- LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists");
+ }
+ if (status == HeatStatus.CREATED) {
+ // fail - it exists
+ if (failIfExists != null && failIfExists) {
+ String error = "Create VF: Stack " + vfModuleName + " already exists in " + cloudSiteId + "/" + tenantId;
+ LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists");
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
- throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ());
- } else {
- LOGGER.debug ("Found Existing stack, status=" + heatStack.getStatus ());
- // Populate the outputs from the existing stack.
- vnfId.value = heatStack.getCanonicalName ();
- outputs.value = copyStringOutputs (heatStack.getOutputs ());
- rollback.value = vfRollback; // Default rollback - no updates performed
- }
- }
+ throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ());
+ } else {
+ LOGGER.debug ("Found Existing stack, status=" + heatStack.getStatus ());
+ // Populate the outputs from the existing stack.
+ vnfId.value = heatStack.getCanonicalName ();
+ outputs.value = copyStringOutputs (heatStack.getOutputs ());
+ rollback.value = vfRollback; // Default rollback - no updates performed
+ }
+ }
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module");
return;
@@ -750,36 +758,36 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
long subStartTime2 = System.currentTimeMillis ();
Map<String, Object> nestedVolumeOutputs = null;
if (nestedStackId != null) {
- try {
- LOGGER.debug("Querying for nestedStackId = " + nestedStackId);
- nestedHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedStackId);
+ try {
+ LOGGER.debug("Querying for nestedStackId = " + nestedStackId);
+ nestedHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedStackId);
LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vfModuleName);
- } catch (MsoException me) {
- // Failed to query the Stack due to an openstack exception.
- // Convert to a generic VnfException
- me.addContext ("CreateVFModule");
- String error = "Create VFModule: Attached heatStack ID Query " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
+ } catch (MsoException me) {
+ // Failed to query the Stack due to an openstack exception.
+ // Convert to a generic VnfException
+ me.addContext ("CreateVFModule");
+ String error = "Create VFModule: Attached heatStack ID Query " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vfModuleName);
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.BusinessProcesssError, "MsoException trying to query nested stack", me);
- LOGGER.debug("ERROR trying to query nested stack= " + error);
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.BusinessProcesssError, "MsoException trying to query nested stack", me);
+ LOGGER.debug("ERROR trying to query nested stack= " + error);
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
- throw new VnfException (me);
- }
- if (nestedHeatStack == null || nestedHeatStack.getStatus() == HeatStatus.NOTFOUND) {
- String error = "Create VFModule: Attached heatStack ID DOES NOT EXIST " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "queryStack", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached heatStack ID DOES NOT EXIST");
+ throw new VnfException (me);
+ }
+ if (nestedHeatStack == null || nestedHeatStack.getStatus() == HeatStatus.NOTFOUND) {
+ String error = "Create VFModule: Attached heatStack ID DOES NOT EXIST " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "queryStack", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached heatStack ID DOES NOT EXIST");
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
- LOGGER.debug(error);
- throw new VnfException (error, MsoExceptionCategory.USERDATA);
- } else {
- LOGGER.debug("Found nested volume heat stack - copying values to inputs *later*");
- //this.sendMapToDebug(inputs);
- nestedVolumeOutputs = nestedHeatStack.getOutputs();
- this.sendMapToDebug(nestedVolumeOutputs, "volumeStackOutputs");
- //TODO
- //heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false);
- //this.sendMapToDebug(inputs);
- }
+ LOGGER.debug(error);
+ throw new VnfException (error, MsoExceptionCategory.USERDATA);
+ } else {
+ LOGGER.debug("Found nested volume heat stack - copying values to inputs *later*");
+ //this.sendMapToDebug(inputs);
+ nestedVolumeOutputs = nestedHeatStack.getOutputs();
+ this.sendMapToDebug(nestedVolumeOutputs, "volumeStackOutputs");
+ //TODO
+ //heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false);
+ //this.sendMapToDebug(inputs);
+ }
}
// handle a nestedBaseStackId if sent- this is the stack ID of the base. Should be null for VNF requests
@@ -787,52 +795,52 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
long subStartTime3 = System.currentTimeMillis ();
Map<String, Object> baseStackOutputs = null;
if (nestedBaseStackId != null) {
- try {
- LOGGER.debug("Querying for nestedBaseStackId = " + nestedBaseStackId);
- nestedBaseHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedBaseStackId);
+ try {
+ LOGGER.debug("Querying for nestedBaseStackId = " + nestedBaseStackId);
+ nestedBaseHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedBaseStackId);
LOGGER.recordMetricEvent (subStartTime3, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vfModuleName);
- } catch (MsoException me) {
- // Failed to query the Stack due to an openstack exception.
- // Convert to a generic VnfException
- me.addContext ("CreateVFModule");
- String error = "Create VFModule: Attached baseHeatStack ID Query " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
+ } catch (MsoException me) {
+ // Failed to query the Stack due to an openstack exception.
+ // Convert to a generic VnfException
+ me.addContext ("CreateVFModule");
+ String error = "Create VFModule: Attached baseHeatStack ID Query " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
LOGGER.recordMetricEvent (subStartTime3, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vfModuleName);
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.BusinessProcesssError, "MsoException trying to query nested base stack", me);
- LOGGER.debug("ERROR trying to query nested base stack= " + error);
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.BusinessProcesssError, "MsoException trying to query nested base stack", me);
+ LOGGER.debug("ERROR trying to query nested base stack= " + error);
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
- throw new VnfException (me);
- }
- if (nestedBaseHeatStack == null || nestedBaseHeatStack.getStatus() == HeatStatus.NOTFOUND) {
- String error = "Create VFModule: Attached base heatStack ID DOES NOT EXIST " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached base heatStack ID DOES NOT EXIST");
+ throw new VnfException (me);
+ }
+ if (nestedBaseHeatStack == null || nestedBaseHeatStack.getStatus() == HeatStatus.NOTFOUND) {
+ String error = "Create VFModule: Attached base heatStack ID DOES NOT EXIST " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached base heatStack ID DOES NOT EXIST");
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
- LOGGER.debug(error);
- throw new VnfException (error, MsoExceptionCategory.USERDATA);
- } else {
- LOGGER.debug("Found nested base heat stack - these values will be copied to inputs *later*");
- //this.sendMapToDebug(inputs);
- baseStackOutputs = nestedBaseHeatStack.getOutputs();
- this.sendMapToDebug(baseStackOutputs, "baseStackOutputs");
- //TODO
- //heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false);
- //this.sendMapToDebug(inputs);
- }
+ LOGGER.debug(error);
+ throw new VnfException (error, MsoExceptionCategory.USERDATA);
+ } else {
+ LOGGER.debug("Found nested base heat stack - these values will be copied to inputs *later*");
+ //this.sendMapToDebug(inputs);
+ baseStackOutputs = nestedBaseHeatStack.getOutputs();
+ this.sendMapToDebug(baseStackOutputs, "baseStackOutputs");
+ //TODO
+ //heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false);
+ //this.sendMapToDebug(inputs);
+ }
}
// Ready to deploy the new VNF
try (CatalogDatabase db = CatalogDatabase.getInstance()) {
// Retrieve the VF
- VfModule vf = null;
- VnfResource vnfResource = null;
- VfModuleCustomization vfmc = null;
- LOGGER.debug("version: " + vfVersion);
+ VfModule vf = null;
+ VnfResource vnfResource = null;
+ VfModuleCustomization vfmc = null;
+ LOGGER.debug("version: " + vfVersion);
if (useMCUuid) {
- // 1707 - db refactoring
- vfmc = db.getVfModuleCustomizationByModelCustomizationId(mcu);
- vf = vfmc != null ? vfmc.getVfModule() : null;
+ // 1707 - db refactoring
+ vfmc = db.getVfModuleCustomizationByModelCustomizationId(mcu);
+ vf = vfmc != null ? vfmc.getVfModule() : null;
// 1702 - this will be the new way going forward. We find the vf by mcu - otherwise, code is the same.
- //vf = db.getVfModuleByModelCustomizationUuid(mcu);
+ //vf = db.getVfModuleByModelCustomizationUuid(mcu);
if (vf == null) {
LOGGER.debug("Unable to find vfModuleCust with modelCustomizationUuid=" + mcu);
String error =
@@ -845,7 +853,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
error);
throw new VnfException(error, MsoExceptionCategory.USERDATA);
} else {
- LOGGER.debug("Found vfModuleCust entry " + vfmc.toString());
+ LOGGER.debug("Found vfModuleCust entry " + vfmc.toString());
}
if (vf.isBase()) {
isBaseRequest = true;
@@ -857,71 +865,24 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
"DANGER WILL ROBINSON! This is unexpected - no nestedBaseStackId with this non-base request");
}
}
- }
- /*
- else if (!oldWay) {
- // Need to handle old and new schema methods - for a time. Try the new way first.
- if (vfVersion != null && !vfVersion.isEmpty()) {
- vf = db.getVfModuleType(vfModuleType, vfVersion);
- if (vf == null) {
- LOGGER.debug("Unable to find " + vfModuleType + " and version=" + vfVersion + " in the TYPE column - will try in MODEL_NAME");
- vf = db.getVfModuleModelName(vfModuleType, vfVersion);
- if (vf == null) {
- LOGGER.debug("Unable to find " + vfModuleType + " and version=" + vfVersion + " in the MODEL_NAME field either - ERROR");
- }
- }
- } else {
- vf = db.getVfModuleType(vfModuleType);
- if (vf == null) {
- LOGGER.debug("Unable to find " + vfModuleType + " in the TYPE column - will try in MODEL_NAME");
- vf = db.getVfModuleModelName(vfModuleType);
- if (vf == null) {
- LOGGER.debug("Unable to find " + vfModuleType + " in the MODEL_NAME field either - ERROR");
- }
- }
- }
- if (vf == null) {
- String error = "Create VF Module: Unable to determine specific VF Module Type: "
- + vfModuleType;
- if (vfVersion != null && !vfVersion.isEmpty()) {
- error += " with version = " + vfVersion;
- }
- LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM,
- "VF Module Type", vfModuleType, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create VF Module: Unable to determine specific VF Module Type");
+ }
+ else { // This is to support gamma only - get info from vnf_resource table
+ if (vfVersion != null && !vfVersion.isEmpty()) {
+ vnfResource = db.getVnfResource(vnfType, vnfVersion);
+ } else {
+ vnfResource = db.getVnfResource(vnfType);
+ }
+ if (vnfResource == null) {
+ String error = "Create VNF: Unknown VNF Type: " + vnfType;
+ LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "VNF Type",
+ vnfType, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create VNF: Unknown VNF Type");
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
- throw new VnfException(error, MsoExceptionCategory.USERDATA);
- }
- LOGGER.debug("Got VF module definition from Catalog: "
- + vf.toString());
-
- if (vf.isBase()) {
- isBaseRequest = true;
- LOGGER.debug("This is a BASE VF request!");
- } else {
- LOGGER.debug("This is *not* a BASE VF request!");
- if (!isVolumeRequest && nestedBaseStackId == null) {
- LOGGER.debug("DANGER WILL ROBINSON! This is unexpected - no nestedBaseStackId with this non-base request");
- }
- }
- } */
- else { // This is to support gamma only - get info from vnf_resource table
- if (vfVersion != null && !vfVersion.isEmpty()) {
- vnfResource = db.getVnfResource(vnfType, vnfVersion);
- } else {
- vnfResource = db.getVnfResource(vnfType);
- }
- if (vnfResource == null) {
- String error = "Create VNF: Unknown VNF Type: " + vnfType;
- LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "VNF Type",
- vnfType, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create VNF: Unknown VNF Type");
- LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
- error);
- throw new VnfException(error, MsoExceptionCategory.USERDATA);
- }
- LOGGER.debug("Got VNF module definition from Catalog: "
- + vnfResource.toString());
- }
- // By here - we have either a vf or vnfResource
+ throw new VnfException(error, MsoExceptionCategory.USERDATA);
+ }
+ LOGGER.debug("Got VNF module definition from Catalog: "
+ + vnfResource.toString());
+ }
+ // By here - we have either a vf or vnfResource
//1607 - Add version check
// First - see if it's in the VnfResource record
@@ -1017,69 +978,49 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// with VNF_RESOURCE - we use the old methods.
//Integer heatTemplateId = null;
//Integer heatEnvtId = null;
-
+
String heatTemplateArtifactUuid = null;
String heatEnvironmentArtifactUuid = null;
- if (!oldWay) {
- if (isVolumeRequest) {
- heatTemplateArtifactUuid = vf.getVolHeatTemplateArtifactUUId();
- heatEnvironmentArtifactUuid = vfmc.getVolEnvironmentArtifactUuid();
- } else {
- heatTemplateArtifactUuid = vf.getHeatTemplateArtifactUUId();
- heatEnvironmentArtifactUuid = vfmc.getHeatEnvironmentArtifactUuid();
- }
- } else {
- if (isVolumeRequest) {
- LOGGER.debug(
- "DANGER WILL ROBINSON! This should never apply - a VNF Request (gamma only now) *and* a volume request?");
- /*
- VnfComponent vnfComponent = null;
- vnfComponent = db.getVnfComponent(vnfResource.getId(), "VOLUME");
- if (vnfComponent == null) {
- String error = "Create VNF: Cannot find VNF Component entry for: " + vnfType + ", type = VOLUME";
- LOGGER.error (MessageEnum.RA_VNF_UNKNOWN_PARAM, "VNF Type", vnfType, "OpenStack", "getVnfComponent", MsoLogger.ErrorCode.DataError, "Create VNF: Cannot find VNF Component entry");
- LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
- throw new VnfException (error, MsoExceptionCategory.USERDATA);
- } else {
- heatTemplateId = vnfComponent.getHeatTemplateId();
- heatEnvtId = vnfComponent.getHeatEnvironmentId();
- }
- */
- } else {
- heatTemplateArtifactUuid = vnfResource.getTemplateId();
- heatEnvironmentArtifactUuid = null;
- }
- }
- // By the time we get here - heatTemplateId and heatEnvtId should be populated (or null)
- HeatTemplate heatTemplate = null;
- if (heatTemplateArtifactUuid == null || "".equals(heatTemplateArtifactUuid)) {
- String error = "Create: No Heat Template ID defined in catalog database for " + vnfType + ", reqType="
- + requestTypeString;
- LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Template ID", vnfType, "OpenStack", "",
- MsoLogger.ErrorCode.DataError, "Create: No Heat Template ID defined in catalog database");
- LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
- error);
- alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR,
- MsoAlarmLogger.CRITICAL, error);
- throw new VnfException(error, MsoExceptionCategory.INTERNAL);
- } else {
- heatTemplate = db.getHeatTemplateByArtifactUuidRegularQuery(heatTemplateArtifactUuid);
- }
- if (heatTemplate == null) {
- String error = "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid;
- LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM,
- "Heat Template ID",
- String.valueOf(heatTemplateArtifactUuid), "OpenStack", "",
- MsoLogger.ErrorCode.BusinessProcesssError,
- "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid);
- LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
- error);
- alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR,
- MsoAlarmLogger.CRITICAL, error);
- throw new VnfException(error, MsoExceptionCategory.INTERNAL);
- }
- LOGGER.debug("Got HEAT Template from DB");
+ if (!oldWay) {
+ if (isVolumeRequest) {
+ heatTemplateArtifactUuid = vf.getVolHeatTemplateArtifactUUId();
+ heatEnvironmentArtifactUuid = vfmc.getVolEnvironmentArtifactUuid();
+ } else {
+ heatTemplateArtifactUuid = vf.getHeatTemplateArtifactUUId();
+ heatEnvironmentArtifactUuid = vfmc.getHeatEnvironmentArtifactUuid();
+ }
+ } else {
+ if (isVolumeRequest) {
+ LOGGER.debug("DANGER WILL ROBINSON! This should never apply - a VNF Request (gamma only now) *and* a volume request?");
+ } else {
+ heatTemplateArtifactUuid = vnfResource.getTemplateId();
+ heatEnvironmentArtifactUuid = null;
+ }
+ }
+ // By the time we get here - heatTemplateId and heatEnvtId should be populated (or null)
+ HeatTemplate heatTemplate = null;
+ if (heatTemplateArtifactUuid == null || "".equals(heatTemplateArtifactUuid)) {
+ String error = "Create: No Heat Template ID defined in catalog database for " + vnfType + ", reqType=" + requestTypeString;
+ LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Template ID", vnfType, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create: No Heat Template ID defined in catalog database");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
+ alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR,
+ MsoAlarmLogger.CRITICAL, error);
+ throw new VnfException(error, MsoExceptionCategory.INTERNAL);
+ } else {
+ heatTemplate = db.getHeatTemplateByArtifactUuidRegularQuery(heatTemplateArtifactUuid);
+ }
+ if (heatTemplate == null) {
+ String error = "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid;
+ LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM,
+ "Heat Template ID",
+ String.valueOf(heatTemplateArtifactUuid), "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
+ alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR,
+ MsoAlarmLogger.CRITICAL, error);
+ throw new VnfException(error, MsoExceptionCategory.INTERNAL);
+ }
+ LOGGER.debug("Got HEAT Template from DB");
HeatEnvironment heatEnvironment = null;
String heatEnvironmentString = null;
@@ -1134,78 +1075,69 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// 1510 - Also add the files: for any get_files associated with this vnf_resource_id
// *if* there are any
Map<String, HeatFiles> heatFiles = null;
- Map<String, Object> heatFilesObjects = new HashMap<>();
+ Map<String, Object> heatFilesObjects = new HashMap<>();
// Add ability to turn on adding get_files with volume requests (by property).
boolean addGetFilesOnVolumeReq = false;
try {
- String propertyString = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER)
- .getProperty(MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ, null);
- if ("true".equalsIgnoreCase(propertyString) || "y".equalsIgnoreCase(propertyString)) {
- addGetFilesOnVolumeReq = true;
- LOGGER.debug("AddGetFilesOnVolumeReq - setting to true! " + propertyString);
- }
+ String propertyString = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER).getProperty(MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ, null);
+ if ("true".equalsIgnoreCase(propertyString) || "y".equalsIgnoreCase(propertyString)) {
+ addGetFilesOnVolumeReq = true;
+ LOGGER.debug("AddGetFilesOnVolumeReq - setting to true! " + propertyString);
+ }
} catch (Exception e) {
- LOGGER.debug("An error occured trying to get property " + MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ
- + " - default to false", e);
- }
-
- if (!isVolumeRequest || addGetFilesOnVolumeReq) {
- if (oldWay) {
- LOGGER.debug(
- "In MsoVnfAdapterImpl createVfModule, this should not happen - old way is gamma only - no heat files!");
- //heatFiles = db.getHeatFiles(vnfResource.getId());
- } else {
- // 1607 - now use VF_MODULE_TO_HEAT_FILES table
- LOGGER.debug(
- "In MsoVnfAdapterImpl createVfModule, about to call db.getHeatFilesForVfModule avec vfModuleId="
- + vf.getModelUUID());
- heatFiles = db
- .getHeatFilesForVfModule(vf.getModelUUID());
- }
- if (heatFiles != null) {
- // add these to stack - to be done in createStack
- // here, we will map them to Map<String, Object> from
- // Map<String, HeatFiles>
- // this will match the nested templates format
- LOGGER.debug("Contents of heatFiles - to be added to files: on stack:");
-
- for (Map.Entry<String, HeatFiles> entry : heatFiles.entrySet()) {
- String heatFileName = entry.getKey();
- HeatFiles value = entry.getValue();
- if (heatFileName.startsWith("_ERROR|")) {
- // This means there was an invalid entry in VF_MODULE_TO_HEAT_FILES table - the heat file it pointed to could not be found.
- String heatFileId = heatFileName.substring(heatFileName.lastIndexOf("|") + 1);
- String error = "Create: No HEAT_FILES entry in catalog database for " + vfModuleType
- + " at HEAT_FILES index=" + heatFileId;
- LOGGER.debug(error);
- LOGGER
- .error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "HEAT_FILES entry not found at " + heatFileId,
- vfModuleType, "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError,
- "HEAT_FILES entry not found");
- LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.DataNotFound, error);
- // Alarm on this error, configuration must be fixed
- alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error);
- throw new VnfException(error, MsoExceptionCategory.INTERNAL);
- }
- String heatFileBody = value.getFileBody();
- String heatFileNameChecked = heatFileName;
- LOGGER.debug(heatFileNameChecked + " -> "
- + heatFileBody);
- heatFilesObjects.put(heatFileNameChecked, heatFileBody);
- }
- } else {
- LOGGER.debug("No heat files found -nothing to do here");
- heatFilesObjects = null;
- }
- } else {
- LOGGER.debug("Volume request - DO NOT CHECK for HEAT_FILES");
- }
+ LOGGER.debug("An error occured trying to get property " + MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ + " - default to false", e);
+ }
+
+ if (!isVolumeRequest || addGetFilesOnVolumeReq) {
+ if (oldWay) {
+ LOGGER.debug("In MsoVnfAdapterImpl createVfModule, this should not happen - old way is gamma only - no heat files!");
+ //heatFiles = db.getHeatFiles(vnfResource.getId());
+ } else {
+ // 1607 - now use VF_MODULE_TO_HEAT_FILES table
+ LOGGER.debug("In MsoVnfAdapterImpl createVfModule, about to call db.getHeatFilesForVfModule avec vfModuleId="
+ + vf.getModelUUID());
+ heatFiles = db
+ .getHeatFilesForVfModule(vf.getModelUUID());
+ }
+ if (heatFiles != null) {
+ // add these to stack - to be done in createStack
+ // here, we will map them to Map<String, Object> from
+ // Map<String, HeatFiles>
+ // this will match the nested templates format
+ LOGGER.debug("Contents of heatFiles - to be added to files: on stack:");
+
+ for (Map.Entry<String, HeatFiles> entry : heatFiles.entrySet()) {
+ String heatFileName = entry.getKey();
+ HeatFiles value = entry.getValue();
+ if (heatFileName.startsWith("_ERROR|")) {
+ // This means there was an invalid entry in VF_MODULE_TO_HEAT_FILES table - the heat file it pointed to could not be found.
+ String heatFileId = heatFileName.substring(heatFileName.lastIndexOf("|")+1);
+ String error = "Create: No HEAT_FILES entry in catalog database for " + vfModuleType + " at HEAT_FILES index=" + heatFileId;
+ LOGGER.debug(error);
+ LOGGER.error (MessageEnum.RA_VNF_UNKNOWN_PARAM, "HEAT_FILES entry not found at " + heatFileId, vfModuleType, "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "HEAT_FILES entry not found");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
+ // Alarm on this error, configuration must be fixed
+ alarmLogger.sendAlarm (MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error);
+ throw new VnfException (error, MsoExceptionCategory.INTERNAL);
+ }
+ String heatFileBody = value.getFileBody();
+ String heatFileNameChecked = heatFileName;
+ LOGGER.debug(heatFileNameChecked + " -> "
+ + heatFileBody);
+ heatFilesObjects.put(heatFileNameChecked, heatFileBody);
+ }
+ } else {
+ LOGGER.debug("No heat files found -nothing to do here");
+ heatFilesObjects = null;
+ }
+ } else {
+ LOGGER.debug("Volume request - DO NOT CHECK for HEAT_FILES");
+ }
// Check that required parameters have been supplied
StringBuilder missingParams = null;
- List<String> paramList = new ArrayList<>();
+ List <String> paramList = new ArrayList <> ();
// New for 1510 - consult the PARAM_ALIAS field to see if we've been
// supplied an alias. Only check if we don't find it initially.
@@ -1232,45 +1164,47 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
MsoHeatEnvironmentEntry mhee = null;
if (heatEnvironmentString != null && heatEnvironmentString.contains("parameters:")) {
//LOGGER.debug ("Have an Environment argument with a parameters: section - will bypass checking for valid params - but will still check for aliases");
- LOGGER.debug("Enhanced environment checking enabled - 1604");
- mhee = MsoHeatEnvironmentEntry.create(heatEnvironmentString);
+ LOGGER.debug("Enhanced environment checking enabled - 1604");
+ StringBuilder sb = new StringBuilder(heatEnvironmentString);
+ //LOGGER.debug("About to create MHEE with " + sb);
+ mhee = new MsoHeatEnvironmentEntry(sb);
StringBuilder sb2 = new StringBuilder("\nHeat Template Parameters:\n");
for (HeatTemplateParam parm : heatTemplate.getParameters()) {
- sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired());
+ sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired());
}
if (!mhee.isValid()) {
- sb2.append("Environment says it's not valid! " + mhee.getErrorString());
+ sb2.append("Environment says it's not valid! " + mhee.getErrorString());
} else {
- sb2.append("\nEnvironment:");
+ sb2.append("\nEnvironment:");
sb2.append(mhee);
}
LOGGER.debug(sb2.toString());
} else {
- LOGGER.debug("NO ENVIRONMENT for this entry");
+ LOGGER.debug("NO ENVIRONMENT for this entry");
}
// New with 1707 - all variables converted to their native object types
HashMap<String, Object> goldenInputs = null;
-
+
LOGGER.debug("Now handle the inputs....first convert");
ArrayList<String> parameterNames = new ArrayList<>();
HashMap<String, String> aliasToParam = new HashMap<>();
StringBuilder sb = new StringBuilder("\nTemplate Parameters:\n");
int cntr = 0;
- try {
- for (HeatTemplateParam htp : heatTemplate.getParameters()) {
- sb.append("param[").append(cntr++).append("]=").append(htp.getParamName());
- parameterNames.add(htp.getParamName());
- if (htp.getParamAlias() != null && !"".equals(htp.getParamAlias())) {
- aliasToParam.put(htp.getParamAlias(), htp.getParamName());
- sb.append(" ** (alias=" + htp.getParamAlias() + ")");
- }
- sb.append("\n");
- }
- LOGGER.debug(sb.toString());
+ try {
+ for (HeatTemplateParam htp : heatTemplate.getParameters()) {
+ sb.append("param[" + cntr++ + "]=" + htp.getParamName());
+ parameterNames.add(htp.getParamName());
+ if (htp.getParamAlias() != null && !"".equals(htp.getParamAlias())) {
+ aliasToParam.put(htp.getParamAlias(), htp.getParamName());
+ sb.append(" ** (alias=" + htp.getParamAlias() + ")");
+ }
+ sb.append("\n");
+ }
+ LOGGER.debug(sb.toString());
} catch (Exception e) {
- LOGGER.debug("??An exception occurred trying to go through Parameter Names " + e.getMessage(), e);
+ LOGGER.debug("??An exception occurred trying to go through Parameter Names " + e.getMessage(),e);
}
- // Step 1 - convert what we got as inputs (Map<String, String>) to a
+ // Step 1 - convert what we got as inputs (Map<String, String>) to a
// Map<String, Object> - where the object matches the param type identified in the template
// This will also not copy over params that aren't identified in the template
goldenInputs = heat.convertInputMap(inputs, heatTemplate);
@@ -1322,13 +1256,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
} else {
LOGGER.debug("No missing parameters found - ok to proceed");
}
- // We can now remove the recreating of the ENV with only legit params - that check is done for us,
+ // We can now remove the recreating of the ENV with only legit params - that check is done for us,
// and it causes problems with json that has arrays
String newEnvironmentString = null;
if (mhee != null) {
- newEnvironmentString = mhee.getRawEntry();
+ newEnvironmentString = mhee.getRawEntry().toString();
}
-
+
// "Fix" the template if it has CR/LF (getting this from Oracle)
String template = heatTemplate.getHeatTemplate();
template = template.replaceAll("\r\n", "\n");
@@ -1396,8 +1330,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
} catch (Exception e) {
LOGGER.debug("unhandled exception in create VF", e);
throw new VnfException("Exception during create VF " + e.getMessage());
-
}
+
// Make sure DB session is closed
// Reach this point if createStack is successful.
@@ -1420,7 +1354,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
MsoRequest msoRequest,
Holder <Map <String, String>> outputs) throws VnfException {
MsoLogger.setLogContext (msoRequest);
- MsoLogger.setServiceName ("DeleteVf");
+ MsoLogger.setServiceName ("DeleteVf");
LOGGER.debug ("Deleting VF " + vnfName + " in " + cloudSiteId + "/" + tenantId);
// Will capture execution time for metrics
long startTime = System.currentTimeMillis ();
@@ -1515,39 +1449,39 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
}
- String requestTypeString = "";
+ String requestTypeString = "";
if (requestType != null && !"".equals(requestType)) {
- requestTypeString = requestType;
+ requestTypeString = requestType;
}
String nestedStackId = null;
if (volumeGroupHeatStackId != null && !"".equals(volumeGroupHeatStackId)) {
- if (!"null".equalsIgnoreCase(volumeGroupHeatStackId)) {
- nestedStackId = volumeGroupHeatStackId;
- }
+ if (!"null".equalsIgnoreCase(volumeGroupHeatStackId)) {
+ nestedStackId = volumeGroupHeatStackId;
+ }
}
String nestedBaseStackId = null;
if (baseVfHeatStackId != null && !"".equals(baseVfHeatStackId)) {
- if (!"null".equalsIgnoreCase(baseVfHeatStackId)) {
- nestedBaseStackId = baseVfHeatStackId;
- }
+ if (!"null".equalsIgnoreCase(baseVfHeatStackId)) {
+ nestedBaseStackId = baseVfHeatStackId;
+ }
}
if (inputs == null) {
- // Create an empty set of inputs
- inputs = new HashMap<>();
- LOGGER.debug("inputs == null - setting to empty");
+ // Create an empty set of inputs
+ inputs = new HashMap<>();
+ LOGGER.debug("inputs == null - setting to empty");
} else {
- this.sendMapToDebug(inputs);
+ this.sendMapToDebug(inputs);
}
boolean isBaseRequest = false;
boolean isVolumeRequest = false;
if (requestTypeString.startsWith("VOLUME")) {
- isVolumeRequest = true;
+ isVolumeRequest = true;
}
if (vfModuleName == null || "".equals(vfModuleName.trim())) {
- if (vfModuleStackId != null) {
- vfModuleName = this.getVfModuleNameFromModuleStackId(vfModuleStackId);
- }
+ if (vfModuleStackId != null) {
+ vfModuleName = this.getVfModuleNameFromModuleStackId(vfModuleStackId);
+ }
}
LOGGER.debug ("Updating VFModule: " + vfModuleName + " of type " + vfModuleType + "in " + cloudSiteId + "/" + tenantId);
@@ -1608,74 +1542,74 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
long queryStackStarttime2 = System.currentTimeMillis ();
Map<String, Object> nestedVolumeOutputs = null;
if (nestedStackId != null) {
- try {
- LOGGER.debug("Querying for nestedStackId = " + nestedStackId);
- nestedHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedStackId);
+ try {
+ LOGGER.debug("Querying for nestedStackId = " + nestedStackId);
+ nestedHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedStackId);
LOGGER.recordMetricEvent (queryStackStarttime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", "QueryStack", null);
- } catch (MsoException me) {
- // Failed to query the Stack due to an openstack exception.
- // Convert to a generic VnfException
- me.addContext ("UpdateVFModule");
- String error = "Update VF: Attached heatStack ID Query " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
+ } catch (MsoException me) {
+ // Failed to query the Stack due to an openstack exception.
+ // Convert to a generic VnfException
+ me.addContext ("UpdateVFModule");
+ String error = "Update VF: Attached heatStack ID Query " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
LOGGER.recordMetricEvent (queryStackStarttime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null);
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - " + error, me);
- LOGGER.debug("ERROR trying to query nested stack= " + error);
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - " + error, me);
+ LOGGER.debug("ERROR trying to query nested stack= " + error);
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
- throw new VnfException (me);
- }
- if (nestedHeatStack == null || nestedHeatStack.getStatus() == HeatStatus.NOTFOUND) {
- MsoLogger.setServiceName (serviceName);
- String error = "Update VFModule: Attached volume heatStack ID DOES NOT EXIST " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error);
- LOGGER.debug(error);
+ throw new VnfException (me);
+ }
+ if (nestedHeatStack == null || nestedHeatStack.getStatus() == HeatStatus.NOTFOUND) {
+ MsoLogger.setServiceName (serviceName);
+ String error = "Update VFModule: Attached volume heatStack ID DOES NOT EXIST " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error);
+ LOGGER.debug(error);
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
- throw new VnfException (error, MsoExceptionCategory.USERDATA);
- } else {
- LOGGER.debug("Found nested heat stack - copying values to inputs *later*");
- nestedVolumeOutputs = nestedHeatStack.getOutputs();
- //this.sendMapToDebug(inputs);
- this.sendMapToDebug(nestedVolumeOutputs, "volumeStackOutputs");
- //TODO
- heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false);
- //this.sendMapToDebug(inputs);
- }
+ throw new VnfException (error, MsoExceptionCategory.USERDATA);
+ } else {
+ LOGGER.debug("Found nested heat stack - copying values to inputs *later*");
+ nestedVolumeOutputs = nestedHeatStack.getOutputs();
+ //this.sendMapToDebug(inputs);
+ this.sendMapToDebug(nestedVolumeOutputs, "volumeStackOutputs");
+ //TODO
+ heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false);
+ //this.sendMapToDebug(inputs);
+ }
}
// handle a nestedBaseStackId if sent - this is the stack ID of the base.
StackInfo nestedBaseHeatStack = null;
Map<String, Object> baseStackOutputs = null;
if (nestedBaseStackId != null) {
long queryStackStarttime3 = System.currentTimeMillis ();
- try {
- LOGGER.debug("Querying for nestedBaseStackId = " + nestedBaseStackId);
- nestedBaseHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedBaseStackId);
+ try {
+ LOGGER.debug("Querying for nestedBaseStackId = " + nestedBaseStackId);
+ nestedBaseHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedBaseStackId);
LOGGER.recordMetricEvent (queryStackStarttime3, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", "QueryStack", null);
- } catch (MsoException me) {
- // Failed to query the Stack due to an openstack exception.
- // Convert to a generic VnfException
- me.addContext ("UpdateVfModule");
- String error = "Update VFModule: Attached baseHeatStack ID Query " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
+ } catch (MsoException me) {
+ // Failed to query the Stack due to an openstack exception.
+ // Convert to a generic VnfException
+ me.addContext ("UpdateVfModule");
+ String error = "Update VFModule: Attached baseHeatStack ID Query " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
LOGGER.recordMetricEvent (queryStackStarttime3, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null);
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - " + error, me);
- LOGGER.debug("ERROR trying to query nested base stack= " + error);
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - " + error, me);
+ LOGGER.debug("ERROR trying to query nested base stack= " + error);
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
- throw new VnfException (me);
- }
- if (nestedBaseHeatStack == null || nestedBaseHeatStack.getStatus() == HeatStatus.NOTFOUND) {
- MsoLogger.setServiceName (serviceName);
- String error = "Update VFModule: Attached base heatStack ID DOES NOT EXIST " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
- LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error);
+ throw new VnfException (me);
+ }
+ if (nestedBaseHeatStack == null || nestedBaseHeatStack.getStatus() == HeatStatus.NOTFOUND) {
+ MsoLogger.setServiceName (serviceName);
+ String error = "Update VFModule: Attached base heatStack ID DOES NOT EXIST " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error);
LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
- LOGGER.debug(error);
- throw new VnfException (error, MsoExceptionCategory.USERDATA);
- } else {
- LOGGER.debug("Found nested base heat stack - copying values to inputs *later*");
- baseStackOutputs = nestedBaseHeatStack.getOutputs();
- //this.sendMapToDebug(inputs);
- this.sendMapToDebug(baseStackOutputs, "baseStackOutputs");
- //TODO
- heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false);
- //this.sendMapToDebug(inputs);
- }
+ LOGGER.debug(error);
+ throw new VnfException (error, MsoExceptionCategory.USERDATA);
+ } else {
+ LOGGER.debug("Found nested base heat stack - copying values to inputs *later*");
+ baseStackOutputs = nestedBaseHeatStack.getOutputs();
+ //this.sendMapToDebug(inputs);
+ this.sendMapToDebug(baseStackOutputs, "baseStackOutputs");
+ //TODO
+ heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false);
+ //this.sendMapToDebug(inputs);
+ }
}
// Ready to deploy the new VNF
@@ -1686,17 +1620,17 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
try (CatalogDatabase db = CatalogDatabase.getInstance()) {
// Retrieve the VF definition
VnfResource vnfResource = null;
- VfModule vf = null;
- VfModuleCustomization vfmc = null;
+ VfModule vf = null;
+ VfModuleCustomization vfmc = null;
if (useMCUuid) {
- //vf = db.getVfModuleByModelCustomizationUuid(mcu);
- vfmc = db.getVfModuleCustomizationByModelCustomizationId(mcu);
- vf = vfmc != null ? vfmc.getVfModule() : null;
+ //vf = db.getVfModuleByModelCustomizationUuid(mcu);
+ vfmc = db.getVfModuleCustomizationByModelCustomizationId(mcu);
+ vf = vfmc != null ? vfmc.getVfModule() : null;
if (vf == null) {
LOGGER.debug("Unable to find a vfModule matching modelCustomizationUuid=" + mcu);
}
- } else {
- LOGGER.debug("1707 and later - MUST PROVIDE Model Customization UUID!");
+ } else {
+ LOGGER.debug("1707 and later - MUST PROVIDE Model Customization UUID!");
}
if (vf == null) {
String error = "Update VfModule: unable to find vfModule with modelCustomizationUuid=" + mcu;
@@ -1707,16 +1641,15 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
LOGGER.debug("Got VF module definition from Catalog: " + vf.toString());
if (vf.isBase()) {
- isBaseRequest = true;
- LOGGER.debug("This a BASE update request");
+ isBaseRequest = true;
+ LOGGER.debug("This a BASE update request");
} else {
LOGGER.debug("This is *not* a BASE VF update request");
if (!isVolumeRequest && nestedBaseStackId == null) {
- LOGGER.debug(
- "DANGER WILL ROBINSON! This is unexpected - no nestedBaseStackId with this non-base request");
+ LOGGER.debug("This is unexpected - no nestedBaseStackId with this non-base request");
}
}
-
+
//1607 - Add version check
// First - see if it's in the VnfResource record
// if we have a vf Module - then we have to query to get the VnfResource record.
@@ -1777,16 +1710,16 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
} // let this error out downstream to avoid introducing uncertainty at this stage
} else {
- LOGGER.debug("cloudConfig is NULL - cannot check cloud site version");
+ LOGGER.debug("cloudConfig is NULL - cannot check cloud site version");
}
- } else {
- LOGGER.debug("AIC Version not set in VNF_Resource - do not error for now - not checked.");
+ } else {
+ LOGGER.debug("AIC Version not set in VNF_Resource - do not error for now - not checked.");
}
- // End Version check 1607
-
- String heatTemplateArtifactUuid = null;
- String heatEnvironmentArtifactUuid = null;
+ // End Version check 1607
+
+ String heatTemplateArtifactUuid = null;
+ String heatEnvironmentArtifactUuid = null;
HeatTemplate heatTemplate = null;
if (isVolumeRequest) {
@@ -1823,8 +1756,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR,
MsoAlarmLogger.CRITICAL, error);
- throw new VnfException(error, MsoExceptionCategory.INTERNAL);
- }
+ throw new VnfException(error, MsoExceptionCategory.INTERNAL);
+ }
LOGGER.debug("Got HEAT Template from DB: " + heatTemplate.toString());
@@ -1906,7 +1839,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
"In MsoVnfAdapterImpl updateVfModule, about to call db.getHeatFilesForVfModule avec vfModuleId="
+ vf.getModelUUID());
- heatFiles = db.getHeatFilesForVfModule(vf.getModelUUID());
+ heatFiles = db.getHeatFilesForVfModule(vf.getModelUUID());
if (heatFiles != null) {
// add these to stack - to be done in createStack
// here, we will map them to Map<String, Object> from Map<String, HeatFiles>
@@ -1971,20 +1904,22 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
MsoHeatEnvironmentEntry mhee = null;
if (heatEnvironmentString != null && heatEnvironmentString.toLowerCase().contains("parameters:")) {
LOGGER.debug("Enhanced environment checking enabled - 1604");
- mhee = MsoHeatEnvironmentEntry.create(heatEnvironmentString);
+ StringBuilder sb = new StringBuilder(heatEnvironmentString);
+ //LOGGER.debug("About to create MHEE with " + sb);
+ mhee = new MsoHeatEnvironmentEntry(sb);
StringBuilder sb2 = new StringBuilder("\nHeat Template Parameters:\n");
for (HeatTemplateParam parm : heatTemplate.getParameters()) {
- sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired());
+ sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired());
}
if (!mhee.isValid()) {
- sb2.append("Environment says it's not valid! " + mhee.getErrorString());
+ sb2.append("Environment says it's not valid! " + mhee.getErrorString());
} else {
- sb2.append("\nEnvironment:");
+ sb2.append("\nEnvironment:");
sb2.append(mhee);
}
LOGGER.debug(sb2.toString());
} else {
- LOGGER.debug("NO ENVIRONMENT for this entry");
+ LOGGER.debug("NO ENVIRONMENT for this entry");
}
// New for 1607 - support params of json type
@@ -2000,7 +1935,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// handle json
String parameterType = parm.getParamType();
if (parameterType == null || "".equals(parameterType.trim())) {
- parameterType = "String";
+ parameterType = "String";
}
JsonNode jsonNode = null;
if ("json".equalsIgnoreCase(parameterType) && inputs != null) {
@@ -2106,7 +2041,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// Just submit the envt entry as received from the database
String newEnvironmentString = null;
if (mhee != null) {
- newEnvironmentString = mhee.getRawEntry();
+ newEnvironmentString = mhee.getRawEntry().toString();
}
// Remove any extraneous parameters (don't throw an error)
@@ -2124,16 +2059,16 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// 1607 - when we get here - we have clean inputs. Create inputsTwo in case we have json
Map<String, Object> inputsTwo = null;
if (hasJson && jsonParams.size() > 0) {
- inputsTwo = new HashMap<>();
- for (Map.Entry<String, String> entry : inputs.entrySet()) {
- String keyParamName = entry.getKey();
- String value = entry.getValue();
- if (jsonParams.containsKey(keyParamName)) {
- inputsTwo.put(keyParamName, jsonParams.get(keyParamName));
- } else {
- inputsTwo.put(keyParamName, value);
- }
- }
+ inputsTwo = new HashMap<>();
+ for (Map.Entry<String, String> entry : inputs.entrySet()) {
+ String keyParamName = entry.getKey();
+ String value = entry.getValue();
+ if (jsonParams.containsKey(keyParamName)) {
+ inputsTwo.put(keyParamName, jsonParams.get(keyParamName));
+ } else {
+ inputsTwo.put(keyParamName, value);
+ }
+ }
}
// "Fix" the template if it has CR/LF (getting this from Oracle)
@@ -2175,8 +2110,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
LOGGER.recordMetricEvent(updateStackStarttime, MsoLogger.StatusCode.COMPLETE,
MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack",
"UpdateStack", null);
-
- }
+ }
} catch (MsoException me) {
me.addContext("UpdateVFModule");
String error = "Update VFModule " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + me;
@@ -2203,21 +2137,21 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
private String getVfModuleNameFromModuleStackId(String vfModuleStackId) {
- // expected format of vfModuleStackId is "MSOTEST51-vSAMP3_base_module-0/1fc1f86c-7b35-447f-99a6-c23ec176ae24"
- // before the "/" is the vfModuleName and after the "/" is the heat stack id in Openstack
- if (vfModuleStackId == null)
- return null;
- int index = vfModuleStackId.lastIndexOf('/');
- if (index <= 0)
- return null;
- String vfModuleName = null;
- try {
- vfModuleName = vfModuleStackId.substring(0, index);
- } catch (Exception e) {
- LOGGER.debug("Exception", e);
- vfModuleName = null;
- }
- return vfModuleName;
+ // expected format of vfModuleStackId is "MSOTEST51-vSAMP3_base_module-0/1fc1f86c-7b35-447f-99a6-c23ec176ae24"
+ // before the "/" is the vfModuleName and after the "/" is the heat stack id in Openstack
+ if (vfModuleStackId == null)
+ return null;
+ int index = vfModuleStackId.lastIndexOf('/');
+ if (index <= 0)
+ return null;
+ String vfModuleName = null;
+ try {
+ vfModuleName = vfModuleStackId.substring(0, index);
+ } catch (Exception e) {
+ LOGGER.debug("Exception", e);
+ vfModuleName = null;
+ }
+ return vfModuleName;
}
}
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfCloudifyAdapterImpl.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfCloudifyAdapterImpl.java
new file mode 100644
index 0000000000..1cd2c165ec
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfCloudifyAdapterImpl.java
@@ -0,0 +1,1256 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.vnf;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import javax.jws.WebService;
+import javax.xml.ws.Holder;
+
+import org.openecomp.mso.adapters.vnf.exceptions.VnfAlreadyExists;
+import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
+import org.openecomp.mso.cloud.CloudConfig;
+import org.openecomp.mso.cloud.CloudConfigFactory;
+import org.openecomp.mso.cloud.CloudSite;
+import org.openecomp.mso.cloudify.beans.DeploymentInfo;
+import org.openecomp.mso.cloudify.beans.DeploymentStatus;
+import org.openecomp.mso.cloudify.exceptions.MsoCloudifyManagerNotFound;
+import org.openecomp.mso.cloudify.utils.MsoCloudifyUtils;
+import org.openecomp.mso.db.catalog.CatalogDatabase;
+import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
+import org.openecomp.mso.db.catalog.beans.HeatFiles;
+import org.openecomp.mso.db.catalog.beans.HeatTemplate;
+import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
+import org.openecomp.mso.db.catalog.beans.VfModule;
+import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
+import org.openecomp.mso.db.catalog.beans.VnfResource;
+import org.openecomp.mso.db.catalog.utils.MavenLikeVersioning;
+import org.openecomp.mso.entity.MsoRequest;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoAlarmLogger;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.openstack.beans.MsoTenant;
+import org.openecomp.mso.openstack.beans.VnfRollback;
+import org.openecomp.mso.openstack.beans.VnfStatus;
+import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+import org.openecomp.mso.openstack.utils.MsoHeatEnvironmentEntry;
+import org.openecomp.mso.openstack.utils.MsoHeatEnvironmentParameter;
+import org.openecomp.mso.openstack.utils.MsoKeystoneUtils;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@WebService(serviceName = "VnfAdapter", endpointInterface = "org.openecomp.mso.adapters.vnf.MsoVnfAdapter", targetNamespace = "http://org.openecomp.mso/vnf")
+public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter {
+
+ CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
+ protected CloudConfig cloudConfig = cloudConfigFactory.getCloudConfig();
+
+ MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory();
+
+ private static final String MSO_PROP_VNF_ADAPTER = "MSO_PROP_VNF_ADAPTER";
+ private static final String MSO_CONFIGURATION_ERROR = "MsoConfigurationError";
+ private static final String VNF_ADAPTER_SERVICE_NAME = "MSO-BPMN:MSO-VnfAdapter.";
+ private static final String LOG_REPLY_NAME = "MSO-VnfAdapter:MSO-BPMN.";
+ private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+ private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
+ private static final String CHECK_REQD_PARAMS = "org.openecomp.mso.adapters.vnf.checkRequiredParameters";
+ private static final String ADD_GET_FILES_ON_VOLUME_REQ = "org.openecomp.mso.adapters.vnf.addGetFilesOnVolumeReq";
+ private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Health Check web method. Does nothing but return to show the adapter is deployed.
+ */
+ @Override
+ public void healthCheck () {
+ LOGGER.debug ("Health check call in VNF Cloudify Adapter");
+ }
+
+ /**
+ * DO NOT use that constructor to instantiate this class, the msoPropertiesfactory will be NULL.
+ * @see MsoVnfCloudifyAdapterImpl#MsoVnfAdapterImpl(MsoPropertiesFactory, CloudConfigFactory)
+ */
+ public MsoVnfCloudifyAdapterImpl() {
+
+ }
+
+ /**
+ * This constructor MUST be used if this class is called with the new operator.
+ * @param msoPropFactory
+ */
+ public MsoVnfCloudifyAdapterImpl(MsoPropertiesFactory msoPropFactory, CloudConfigFactory cloudConfigFact) {
+ this.msoPropertiesFactory = msoPropFactory;
+ this.cloudConfigFactory = cloudConfigFact;
+ }
+
+ /**
+ * This is the "Create VNF" web service implementation.
+ * This function is now unsupported and will return an error.
+ *
+ */
+ @Override
+ public void createVnf (String cloudSiteId,
+ String tenantId,
+ String vnfType,
+ String vnfVersion,
+ String vnfName,
+ String requestType,
+ String volumeGroupHeatStackId,
+ Map <String, String> inputs,
+ Boolean failIfExists,
+ Boolean backout,
+ MsoRequest msoRequest,
+ Holder <String> vnfId,
+ Holder <Map <String, String>> outputs,
+ Holder <VnfRollback> rollback)
+ throws VnfException
+ {
+ // This operation is no longer supported at the VNF level. The adapter is only called to deploy modules.
+ LOGGER.debug ("CreateVNF command attempted but not supported");
+ throw new VnfException ("CreateVNF: Unsupported command", MsoExceptionCategory.USERDATA);
+ }
+
+ /**
+ * This is the "Update VNF" web service implementation.
+ * This function is now unsupported and will return an error.
+ *
+ */
+ @Override
+ public void updateVnf (String cloudSiteId,
+ String tenantId,
+ String vnfType,
+ String vnfVersion,
+ String vnfName,
+ String requestType,
+ String volumeGroupHeatStackId,
+ Map <String, String> inputs,
+ MsoRequest msoRequest,
+ Holder <Map <String, String>> outputs,
+ Holder <VnfRollback> rollback)
+ throws VnfException
+ {
+ // This operation is no longer supported at the VNF level. The adapter is only called to deploy modules.
+ LOGGER.debug ("UpdateVNF command attempted but not supported");
+ throw new VnfException ("UpdateVNF: Unsupported command", MsoExceptionCategory.USERDATA);
+ }
+
+ /**
+ * This is the "Query VNF" web service implementation.
+ *
+ * This really should be QueryVfModule, but nobody ever changed it.
+ *
+ * For Cloudify, this will look up a deployment by its deployment ID, which is really the same
+ * as deployment name, since it assigned by the client when a deployment is created.
+ * Also, the input cloudSiteId is used only to identify which Cloudify instance to query,
+ * and the tenantId is ignored (since that really only applies for Openstack/Heat).
+ *
+ * The method returns an indicator that the VNF exists, along with its status and outputs.
+ * The input "vnfName" will also be reflected back as its ID.
+ *
+ * @param cloudSiteId CLLI code of the cloud site in which to query
+ * @param tenantId Openstack tenant identifier - ignored for Cloudify
+ * @param vnfName VNF Name (should match a deployment ID)
+ * @param msoRequest Request tracking information for logs
+ * @param vnfExists Flag reporting the result of the query
+ * @param vnfId Holder for output VNF ID
+ * @param outputs Holder for Map of VNF outputs from Cloudify deployment (assigned IPs, etc)
+ */
+ @Override
+ public void queryVnf (String cloudSiteId,
+ String tenantId,
+ String vnfName,
+ MsoRequest msoRequest,
+ Holder <Boolean> vnfExists,
+ Holder <String> vnfId,
+ Holder <VnfStatus> status,
+ Holder <Map <String, String>> outputs)
+ throws VnfException
+ {
+ MsoLogger.setLogContext (msoRequest);
+ MsoLogger.setServiceName ("QueryVnfCloudify");
+ LOGGER.debug ("Querying VNF " + vnfName + " in " + cloudSiteId + "/" + tenantId);
+
+ // Will capture execution time for metrics
+ long startTime = System.currentTimeMillis ();
+ long subStartTime = System.currentTimeMillis ();
+
+ MsoCloudifyUtils cloudifyUtils = new MsoCloudifyUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory);
+ DeploymentInfo deployment = null;
+
+ try {
+ deployment = cloudifyUtils.queryDeployment(cloudSiteId, tenantId, vnfName);
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Cloudify", "Cloudify", "QueryDeployment", vnfName);
+ }
+ catch (MsoCloudifyManagerNotFound e) {
+ // This site does not have a Cloudify Manager.
+ // This isn't an error, just means we won't find the VNF here.
+ deployment = null;
+ }
+ catch (MsoException me) {
+ // Failed to query the Deployment due to a cloudify exception.
+ // Convert to a generic VnfException
+ me.addContext ("QueryVNF");
+ String error = "Query VNF (Cloudify): " + vnfName + " in " + cloudSiteId + "/" + tenantId + ": " + me;
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "Cloudify", "QueryDeployment", vnfName);
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "Cloudify", "QueryVNF", MsoLogger.ErrorCode.DataError, "Exception - queryDeployment", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new VnfException (me);
+ }
+
+ if (deployment != null && deployment.getStatus() != DeploymentStatus.NOTFOUND) {
+ vnfExists.value = Boolean.TRUE;
+ status.value = deploymentStatusToVnfStatus(deployment);
+ vnfId.value = deployment.getId();
+ outputs.value = copyStringOutputs (deployment.getOutputs ());
+
+ LOGGER.debug ("VNF " + vnfName + " found in Cloudify, ID = " + vnfId.value);
+ }
+ else {
+ vnfExists.value = Boolean.FALSE;
+ status.value = VnfStatus.NOTFOUND;
+ vnfId.value = null;
+ outputs.value = new HashMap <String, String> (); // Return as an empty map
+
+ LOGGER.debug ("VNF " + vnfName + " not found");
+ }
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully query VNF");
+ return;
+ }
+
+
+ /**
+ * This is the "Delete VNF" web service implementation.
+ * This function is now unsupported and will return an error.
+ *
+ */
+ @Override
+ public void deleteVnf (String cloudSiteId,
+ String tenantId,
+ String vnfName,
+ MsoRequest msoRequest) throws VnfException {
+ MsoLogger.setLogContext (msoRequest);
+ MsoLogger.setServiceName ("DeleteVnf");
+
+ // This operation is no longer supported at the VNF level. The adapter is only called to deploy modules.
+ LOGGER.debug ("DeleteVNF command attempted but not supported");
+ throw new VnfException ("DeleteVNF: Unsupported command", MsoExceptionCategory.USERDATA);
+ }
+
+ /**
+ * This web service endpoint will rollback a previous Create VNF operation.
+ * A rollback object is returned to the client in a successful creation
+ * response. The client can pass that object as-is back to the rollbackVnf
+ * operation to undo the creation.
+ *
+ * TODO: This should be rollbackVfModule and/or rollbackVolumeGroup,
+ * but APIs were apparently never updated.
+ */
+ @Override
+ public void rollbackVnf (VnfRollback rollback) throws VnfException {
+ long startTime = System.currentTimeMillis ();
+ MsoLogger.setServiceName ("RollbackVnf");
+ // rollback may be null (e.g. if stack already existed when Create was called)
+ if (rollback == null) {
+ LOGGER.info (MessageEnum.RA_ROLLBACK_NULL, "OpenStack", "rollbackVnf");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Rollback request content is null");
+ return;
+ }
+
+ // Don't rollback if nothing was done originally
+ if (!rollback.getVnfCreated()) {
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Rollback VF Module - nothing to roll back");
+ return;
+ }
+
+ // Get the elements of the VnfRollback object for easier access
+ String cloudSiteId = rollback.getCloudSiteId ();
+ String tenantId = rollback.getTenantId ();
+ String vfModuleId = rollback.getVfModuleStackId ();
+
+ MsoLogger.setLogContext (rollback.getMsoRequest());
+
+ LOGGER.debug ("Rolling Back VF Module " + vfModuleId + " in " + cloudSiteId + "/" + tenantId);
+
+ MsoCloudifyUtils cloudifyUtils = new MsoCloudifyUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory);
+ DeploymentInfo deployment = null;
+
+ // Use the MsoCloudifyUtils to delete the deployment. Set the polling flag to true.
+ // The possible outcomes of deleteStack are a StackInfo object with status
+ // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException
+ // could be thrown.
+ long subStartTime = System.currentTimeMillis ();
+ try {
+ // KLUDGE - Cloudify requires Tenant Name for Openstack. We have the ID.
+ // Go directly to Keystone until APIs could be updated to supply the name.
+ MsoKeystoneUtils keystone = new MsoKeystoneUtils(MSO_PROP_VNF_ADAPTER);
+ MsoTenant msoTenant = keystone.queryTenant(tenantId, cloudSiteId);
+ String tenantName = (msoTenant != null? msoTenant.getTenantName() : tenantId);
+
+ // TODO: Get a reasonable timeout. Use a global property, or store the creation timeout in rollback object and use that.
+ deployment = cloudifyUtils.uninstallAndDeleteDeployment(cloudSiteId, tenantName, vfModuleId, 5);
+ LOGGER.debug("Rolled back deployment: " + deployment.getId());
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Cloudify", "Cloudify", "DeleteDeployment", null);
+ } catch (MsoException me) {
+ // Failed to rollback the VNF due to a cloudify exception.
+ // Convert to a generic VnfException
+ me.addContext ("RollbackVNF");
+ String error = "Rollback VF Module: " + vfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + me;
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "Cloudify", "DeleteDeployment", null);
+ LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vfModuleId, cloudSiteId, tenantId, "Cloudify", "DeleteDeployment", MsoLogger.ErrorCode.DataError, "Exception - DeleteDeployment", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new VnfException (me);
+ }
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully roll back VF Module");
+ return;
+ }
+
+
+ private VnfStatus deploymentStatusToVnfStatus (DeploymentInfo deployment) {
+ // Determine the status based on last action & status
+ // DeploymentInfo object should be enhanced to report a better status internally.
+ DeploymentStatus status = deployment.getStatus();
+ String lastAction = deployment.getLastAction();
+
+ if (status == null || lastAction == null) {
+ return VnfStatus.UNKNOWN;
+ }
+ else if (status == DeploymentStatus.NOTFOUND) {
+ return VnfStatus.NOTFOUND;
+ }
+ else if (status == DeploymentStatus.INSTALLED) {
+ return VnfStatus.ACTIVE;
+ }
+ else if (status == DeploymentStatus.CREATED) {
+ // Should have an INACTIVE status for this case. Shouldn't really happen, but
+ // Install was never run, or Uninstall was done but deployment didn't get deleted.
+ return VnfStatus.UNKNOWN;
+ }
+ else if (status == DeploymentStatus.FAILED) {
+ return VnfStatus.FAILED;
+ }
+
+ return VnfStatus.UNKNOWN;
+ }
+
+ private Map <String, String> copyStringOutputs (Map <String, Object> stackOutputs) {
+ Map <String, String> stringOutputs = new HashMap <String, String> ();
+ for (String key : stackOutputs.keySet ()) {
+ if (stackOutputs.get (key) instanceof String) {
+ stringOutputs.put (key, (String) stackOutputs.get (key));
+ } else if (stackOutputs.get(key) instanceof Integer) {
+ try {
+ String str = "" + stackOutputs.get(key);
+ stringOutputs.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("Unable to add " + key + " to outputs");
+ }
+ } else if (stackOutputs.get(key) instanceof JsonNode) {
+ try {
+ String str = this.convertNode((JsonNode) stackOutputs.get(key));
+ stringOutputs.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("Unable to add " + key + " to outputs - exception converting JsonNode");
+ }
+ } else if (stackOutputs.get(key) instanceof java.util.LinkedHashMap) {
+ try {
+ String str = JSON_MAPPER.writeValueAsString(stackOutputs.get(key));
+ stringOutputs.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("Unable to add " + key + " to outputs - exception converting LinkedHashMap");
+ }
+ } else {
+ try {
+ String str = stackOutputs.get(key).toString();
+ stringOutputs.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("Unable to add " + key + " to outputs - unable to call .toString() " + e.getMessage());
+ }
+ }
+ }
+ return stringOutputs;
+ }
+
+
+ private void sendMapToDebug(Map<String, Object> inputs, String optionalName) {
+ int i = 0;
+ StringBuilder sb = new StringBuilder(optionalName == null ? "\ninputs" : "\n" + optionalName);
+ if (inputs == null) {
+ sb.append("\tNULL");
+ }
+ else if (inputs.size() < 1) {
+ sb.append("\tEMPTY");
+ } else {
+ for (String str : inputs.keySet()) {
+ String outputString;
+ try {
+ outputString = inputs.get(str).toString();
+ } catch (Exception e) {
+ outputString = "Unable to call toString() on the value for " + str;
+ }
+ sb.append("\t\nitem " + i++ + ": '" + str + "'='" + outputString + "'");
+ }
+ }
+ LOGGER.debug(sb.toString());
+ return;
+ }
+
+ private void sendMapToDebug(Map<String, String> inputs) {
+ int i = 0;
+ StringBuilder sb = new StringBuilder("inputs:");
+ if (inputs == null) {
+ sb.append("\tNULL");
+ }
+ else if (inputs.size() < 1) {
+ sb.append("\tEMPTY");
+ } else {
+ for (String str : inputs.keySet()) {
+ sb.append("\titem " + i++ + ": " + str + "=" + inputs.get(str));
+ }
+ }
+ LOGGER.debug(sb.toString());
+ return;
+ }
+
+ private String convertNode(final JsonNode node) {
+ try {
+ final Object obj = JSON_MAPPER.treeToValue(node, Object.class);
+ final String json = JSON_MAPPER.writeValueAsString(obj);
+ return json;
+ } catch (JsonParseException jpe) {
+ LOGGER.debug("Error converting json to string " + jpe.getMessage());
+ } catch (Exception e) {
+ LOGGER.debug("Error converting json to string " + e.getMessage());
+ }
+ return "[Error converting json to string]";
+ }
+
+ private Map<String, String> convertMapStringObjectToStringString(Map<String, Object> objectMap) {
+ if (objectMap == null) {
+ return null;
+ }
+ Map<String, String> stringMap = new HashMap<String, String>();
+ for (String key : objectMap.keySet()) {
+ if (!stringMap.containsKey(key)) {
+ Object obj = objectMap.get(key);
+ if (obj instanceof String) {
+ stringMap.put(key, (String) objectMap.get(key));
+ } else if (obj instanceof JsonNode ){
+ // This is a bit of mess - but I think it's the least impacting
+ // let's convert it BACK to a string - then it will get converted back later
+ try {
+ String str = this.convertNode((JsonNode) obj);
+ stringMap.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for JsonNode "+ key);
+ //okay in this instance - only string values (fqdn) are expected to be needed
+ }
+ } else if (obj instanceof java.util.LinkedHashMap) {
+ LOGGER.debug("LinkedHashMap - this is showing up as a LinkedHashMap instead of JsonNode");
+ try {
+ String str = JSON_MAPPER.writeValueAsString(obj);
+ stringMap.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for LinkedHashMap "+ key);
+ }
+ } else if (obj instanceof Integer) {
+ try {
+ String str = "" + obj;
+ stringMap.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for Integer "+ key);
+ }
+ } else {
+ try {
+ String str = obj.toString();
+ stringMap.put(key, str);
+ } catch (Exception e) {
+ LOGGER.debug("DANGER WILL ROBINSON: unable to convert value "+ key + " (" + e.getMessage() + ")");
+ }
+ }
+ }
+ }
+
+ return stringMap;
+ }
+
+ /**
+ * This is the "Create VF Module" web service implementation.
+ * It will instantiate a new VF Module of the requested type in the specified cloud
+ * and tenant. The tenant must exist before this service is called.
+ *
+ * If a VF Module with the same name already exists, this can be considered a
+ * success or failure, depending on the value of the 'failIfExists' parameter.
+ *
+ * All VF Modules are defined in the MSO catalog. The caller must request
+ * one of the pre-defined module types or an error will be returned. Within the
+ * catalog, each VF Module references (among other things) a cloud template
+ * which is used to deploy the required artifacts (VMs, networks, etc.)
+ * to the cloud. In this adapter implementation, that artifact is expected
+ * to be a Cloudify blueprint.
+ *
+ * Depending on the blueprint, a variable set of input parameters will
+ * be defined, some of which are required. The caller is responsible to
+ * pass the necessary input data for the module or an error will be thrown.
+ *
+ * The method returns the vfModuleId, a Map of output attributes, and a VnfRollback
+ * object. This last object can be passed as-is to the rollbackVnf operation to
+ * undo everything that was created for the Module. This is useful if a VF module
+ * is successfully created but the orchestration fails on a subsequent step.
+ *
+ * @param cloudSiteId CLLI code of the cloud site in which to create the VNF
+ * @param tenantId Openstack tenant identifier
+ * @param vfModuleType VF Module type key, should match a VNF definition in catalog DB.
+ * Deprecated - should use modelCustomizationUuid
+ * @param vnfVersion VNF version key, should match a VNF definition in catalog DB
+ * Deprecated - VF Module versions also captured by modelCustomizationUuid
+ * @param vfModuleName Name to be assigned to the new VF Module
+ * @param requestType Indicates if this is a Volume Group or Module request
+ * @param volumeGroupId Identifier (i.e. deployment ID) for a Volume Group
+ * to attach to a VF Module
+ * @param baseVfModuleId Identifier (i.e. deployment ID) of the Base Module if
+ * this is an Add-on module
+ * @param modelCustomizationUuid Unique ID for the VF Module's model. Replaces
+ * the use of vfModuleType.
+ * @param inputs Map of key=value inputs for VNF stack creation
+ * @param failIfExists Flag whether already existing VNF should be considered
+ * @param backout Flag whether to suppress automatic backout (for testing)
+ * @param msoRequest Request tracking information for logs
+ * @param vnfId Holder for output VNF Cloudify Deployment ID
+ * @param outputs Holder for Map of VNF outputs from Deployment (assigned IPs, etc)
+ * @param rollback Holder for returning VnfRollback object
+ */
+ public void createVfModule(String cloudSiteId,
+ String tenantId,
+ String vfModuleType,
+ String vnfVersion,
+ String vfModuleName,
+ String requestType,
+ String volumeGroupId,
+ String baseVfModuleId,
+ String modelCustomizationUuid,
+ Map <String, String> inputs,
+ Boolean failIfExists,
+ Boolean backout,
+ MsoRequest msoRequest,
+ Holder <String> vnfId,
+ Holder <Map <String, String>> outputs,
+ Holder <VnfRollback> rollback)
+ throws VnfException
+ {
+ // Will capture execution time for metrics
+ long startTime = System.currentTimeMillis ();
+
+ MsoLogger.setLogContext (msoRequest);
+ MsoLogger.setServiceName ("CreateVfModule");
+
+ // Require a model customization ID. Every VF Module definition must have one.
+ if (modelCustomizationUuid == null || modelCustomizationUuid.isEmpty()) {
+ LOGGER.debug("Missing required input: modelCustomizationUuid");
+ String error = "Create vfModule error: Missing required input: modelCustomizationUuid";
+ LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM,
+ "VF Module ModelCustomizationUuid", "null", "Cloudify", "", MsoLogger.ErrorCode.DataError, "Create VF Module: Missing required input: modelCustomizationUuid");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
+ throw new VnfException(error, MsoExceptionCategory.USERDATA);
+ }
+
+ // Clean up some inputs to make comparisons easier
+ if (requestType == null)
+ requestType = "";
+
+ if ("".equals(volumeGroupId) || "null".equals(volumeGroupId))
+ volumeGroupId = null;
+
+ if ("".equals(baseVfModuleId) || "null".equals(baseVfModuleId))
+ baseVfModuleId = null;
+
+ if (inputs == null) {
+ // Create an empty set of inputs
+ inputs = new HashMap<String,String>();
+ LOGGER.debug("inputs == null - setting to empty");
+ } else {
+ this.sendMapToDebug(inputs);
+ }
+
+ // Check if this is for a "Volume" module
+ boolean isVolumeRequest = false;
+ if (requestType.startsWith("VOLUME")) {
+ isVolumeRequest = true;
+ }
+
+ LOGGER.debug("requestType = " + requestType + ", volumeGroupStackId = " + volumeGroupId + ", baseStackId = " + baseVfModuleId);
+
+ // Build a default rollback object (no actions performed)
+ VnfRollback vfRollback = new VnfRollback();
+ vfRollback.setCloudSiteId(cloudSiteId);
+ vfRollback.setTenantId(tenantId);
+ vfRollback.setMsoRequest(msoRequest);
+ vfRollback.setRequestType(requestType);
+ vfRollback.setIsBase(false); // Until we know better
+ vfRollback.setVolumeGroupHeatStackId(volumeGroupId);
+ vfRollback.setBaseGroupHeatStackId(baseVfModuleId);
+ vfRollback.setModelCustomizationUuid(modelCustomizationUuid);
+ vfRollback.setMode("CFY");
+
+ rollback.value = vfRollback; // Default rollback - no updates performed
+
+ // Get the VNF/VF Module definition from the Catalog DB first.
+ // There are three relevant records: VfModule, VfModuleCustomization, VnfResource
+
+ CatalogDatabase db = CatalogDatabase.getInstance();
+ VfModule vf = null;
+ VnfResource vnfResource = null;
+ VfModuleCustomization vfmc = null;
+
+ try {
+ vfmc = db.getVfModuleCustomizationByModelCustomizationId(modelCustomizationUuid);
+
+ if (vfmc == null) {
+ String error = "Create vfModule error: Unable to find vfModuleCust with modelCustomizationUuid=" + modelCustomizationUuid;
+ LOGGER.debug(error);
+ LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM,
+ "VF Module ModelCustomizationUuid", modelCustomizationUuid, "CatalogDb", "", MsoLogger.ErrorCode.DataError, error);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
+ throw new VnfException(error, MsoExceptionCategory.USERDATA);
+ } else {
+ LOGGER.debug("Found vfModuleCust entry " + vfmc.toString());
+ }
+
+ // Get the vfModule and vnfResource records
+ vf = vfmc.getVfModule();
+ vnfResource = db.getVnfResourceByModelUuid(vf.getVnfResourceModelUUId());
+ }
+ catch (Exception e) {
+ db.close ();
+ LOGGER.debug("unhandled exception in create VF - [Query]" + e.getMessage());
+ throw new VnfException("Exception during create VF " + e.getMessage());
+ }
+
+ // Perform a version check against cloudSite
+ // Obtain the cloud site information where we will create the VF Module
+ Optional<CloudSite> cloudSite = cloudConfig.getCloudSite (cloudSiteId);
+ if (!cloudSite.isPresent()) {
+ throw new VnfException (new MsoCloudSiteNotFound (cloudSiteId));
+ }
+ MavenLikeVersioning aicV = new MavenLikeVersioning();
+ aicV.setVersion(cloudSite.get().getAic_version());
+
+ String vnfMin = vnfResource.getAicVersionMin();
+ String vnfMax = vnfResource.getAicVersionMax();
+
+ if ( (vnfMin != null && !(aicV.isMoreRecentThan(vnfMin) || aicV.isTheSameVersion(vnfMin))) ||
+ (vnfMax != null && aicV.isMoreRecentThan(vnfMax)))
+ {
+ // ERROR
+ String error = "VNF Resource type: " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource.getModelUuid() + " VersionMin=" + vnfMin + " VersionMax:" + vnfMax + " NOT supported on Cloud: " + cloudSite.get().getId() + " with AIC_Version:" + cloudSite.get().getAic_version();
+ LOGGER.error(MessageEnum.RA_CONFIG_EXC, error, "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - setVersion");
+ LOGGER.debug(error);
+ throw new VnfException(error, MsoExceptionCategory.USERDATA);
+ }
+ // End Version check
+
+
+ // Get Utilities for Cloudify.
+ MsoCloudifyUtils cloudify = new MsoCloudifyUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory);
+ DeploymentInfo cloudifyDeployment = null;
+
+ // First, look up to see if the VF already exists.
+
+ long subStartTime1 = System.currentTimeMillis ();
+ try {
+ cloudifyDeployment = cloudify.queryDeployment (cloudSiteId, tenantId, vfModuleName);
+ LOGGER.recordMetricEvent (subStartTime1, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Cloudify", "Cloudify", "QueryDeployment", vfModuleName);
+ }
+ catch (MsoException me) {
+ // Failed to query the Deployment due to a cloudify exception.
+ String error = "Create VF Module: Query " + vfModuleName + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "Cloudify", "queryDeployment", MsoLogger.ErrorCode.DataError, "Exception - queryDeployment", me);
+ LOGGER.recordMetricEvent (subStartTime1, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "Cloudify", "QueryDeployment", vfModuleName);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+
+ // Convert to a generic VnfException
+ me.addContext ("CreateVFModule");
+ throw new VnfException (me);
+ }
+
+ // More precise handling/messaging if the Module already exists
+ if (cloudifyDeployment != null && !(cloudifyDeployment.getStatus () == DeploymentStatus.NOTFOUND)) {
+ // CREATED, INSTALLED, INSTALLING, FAILED, UNINSTALLING, UNKNOWN
+ DeploymentStatus status = cloudifyDeployment.getStatus();
+ LOGGER.debug ("Found Existing Deployment, status=" + status);
+
+ if (status == DeploymentStatus.INSTALLED) {
+ // fail - it exists
+ if (failIfExists != null && failIfExists) {
+ String error = "Create VF: Deployment " + vfModuleName + " already exists in " + cloudSiteId + "/" + tenantId;
+ LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "Cloudify", "queryDeployment", MsoLogger.ErrorCode.DataError, "Deployment " + vfModuleName + " already exists");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
+ throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, cloudifyDeployment.getId());
+ } else {
+ // Found existing deployment and client has not requested "failIfExists".
+ // Populate the outputs from the existing deployment.
+
+ vnfId.value = cloudifyDeployment.getId();
+ outputs.value = copyStringOutputs (cloudifyDeployment.getOutputs ());
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module (found existing)");
+ return;
+ }
+ }
+ // Check through various detailed error cases
+ if (status == DeploymentStatus.INSTALLING || status == DeploymentStatus.UNINSTALLING) {
+ // fail - it's in progress - return meaningful error
+ String error = "Create VF: Deployment " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; please wait for it to complete, or fix manually.";
+ LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "Cloudify", "queryDeployment", MsoLogger.ErrorCode.DataError, "Deployment " + vfModuleName + " already exists");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
+ throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, cloudifyDeployment.getId());
+ }
+ else if (status == DeploymentStatus.FAILED) {
+ // fail - it exists and is in a FAILED state
+ String error = "Create VF: Deployment " + vfModuleName + " already exists and is in FAILED state in " + cloudSiteId + "/" + tenantId + "; requires manual intervention.";
+ LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "Cloudify", "queryDeployment", MsoLogger.ErrorCode.DataError, "Deployment " + vfModuleName + " already exists and is in FAILED state");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
+ throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, cloudifyDeployment.getId());
+ }
+ else if (status == DeploymentStatus.UNKNOWN || status == DeploymentStatus.CREATED) {
+ // fail - it exists and is in a UNKNOWN state
+ String error = "Create VF: Deployment " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; requires manual intervention.";
+ LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "Cloudify", "queryDeployment", MsoLogger.ErrorCode.DataError, "Deployment " + vfModuleName + " already exists and is in " + status.toString() + " state");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
+ throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, cloudifyDeployment.getId());
+ }
+ else {
+ // Unexpected, since all known status values have been tested for
+ String error = "Create VF: Deployment " + vfModuleName + " already exists with unexpected status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; requires manual intervention.";
+ LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "Cloudify", "queryDeployment", MsoLogger.ErrorCode.DataError, "Deployment " + vfModuleName + " already exists and is in an unknown state");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
+ throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, cloudifyDeployment.getId());
+ }
+ }
+
+
+ // Collect outputs from Base Modules and Volume Modules
+ Map<String, Object> baseModuleOutputs = null;
+ Map<String, Object> volumeGroupOutputs = null;
+
+ // If a Volume Group was provided, query its outputs for inclusion in Module input parameters
+ if (volumeGroupId != null) {
+ long subStartTime2 = System.currentTimeMillis ();
+ DeploymentInfo volumeDeployment = null;
+ try {
+ volumeDeployment = cloudify.queryDeployment (cloudSiteId, tenantId, volumeGroupId);
+ LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Success response from Cloudify", "Cloudify", "QueryDeployment", volumeGroupId);
+ }
+ catch (MsoException me) {
+ // Failed to query the Volume GroupDeployment due to a cloudify exception.
+ String error = "Create VF Module: Query Volume Group " + volumeGroupId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, volumeGroupId, cloudSiteId, tenantId, "Cloudify", "queryDeployment(volume)", MsoLogger.ErrorCode.DataError, "Exception - queryDeployment(volume)", me);
+ LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "Cloudify", "QueryDeployment(volume)", volumeGroupId);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+
+ // Convert to a generic VnfException
+ me.addContext ("CreateVFModule(QueryVolume)");
+ throw new VnfException (me);
+ }
+
+ if (volumeDeployment == null || volumeDeployment.getStatus() == DeploymentStatus.NOTFOUND) {
+ String error = "Create VFModule: Attached Volume Group DOES NOT EXIST " + volumeGroupId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, volumeGroupId, cloudSiteId, tenantId, error, "Cloudify", "queryDeployment(volume)", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached Volume Group DOES NOT EXIST");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
+ LOGGER.debug(error);
+ throw new VnfException (error, MsoExceptionCategory.USERDATA);
+ } else {
+ LOGGER.debug("Found nested volume group");
+ volumeGroupOutputs = volumeDeployment.getOutputs();
+ this.sendMapToDebug(volumeGroupOutputs, "volumeGroupOutputs");
+ }
+ }
+
+ // If this is an Add-On Module, query the Base Module outputs
+ // Note: This will be performed whether or not the current request is for an
+ // Add-On Volume Group or Add-On VF Module
+
+ if (vf.isBase()) {
+ LOGGER.debug("This is a BASE Module request");
+ vfRollback.setIsBase(true);
+ } else {
+ LOGGER.debug("This is an Add-On Module request");
+
+ // Add-On Modules should always have a Base, but just treat as a warning if not provided.
+ // Add-on Volume requests may or may not specify a base.
+ if (!isVolumeRequest && baseVfModuleId == null) {
+ LOGGER.debug ("WARNING: Add-on Module request - no Base Module ID provided");
+ }
+
+ if (baseVfModuleId != null) {
+ long subStartTime2 = System.currentTimeMillis ();
+ DeploymentInfo baseDeployment = null;
+ try {
+ baseDeployment = cloudify.queryDeployment (cloudSiteId, tenantId, baseVfModuleId);
+ LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Success response from Cloudify", "Cloudify", "QueryDeployment(Base)", baseVfModuleId);
+ }
+ catch (MsoException me) {
+ // Failed to query the Volume GroupDeployment due to a cloudify exception.
+ String error = "Create VF Module: Query Base " + baseVfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, baseVfModuleId, cloudSiteId, tenantId, "Cloudify", "queryDeployment(Base)", MsoLogger.ErrorCode.DataError, "Exception - queryDeployment(Base)", me);
+ LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "Cloudify", "QueryDeployment(Base)", baseVfModuleId);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+
+ // Convert to a generic VnfException
+ me.addContext ("CreateVFModule(QueryBase)");
+ throw new VnfException (me);
+ }
+
+ if (baseDeployment == null || baseDeployment.getStatus() == DeploymentStatus.NOTFOUND) {
+ String error = "Create VFModule: Base Module DOES NOT EXIST " + baseVfModuleId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ;
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, baseVfModuleId, cloudSiteId, tenantId, error, "Cloudify", "queryDeployment(Base)", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Base Module DOES NOT EXIST");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
+ LOGGER.debug(error);
+ throw new VnfException (error, MsoExceptionCategory.USERDATA);
+ } else {
+ LOGGER.debug("Found base module");
+ baseModuleOutputs = baseDeployment.getOutputs();
+ this.sendMapToDebug(baseModuleOutputs, "baseModuleOutputs");
+ }
+ }
+ }
+
+
+ // Ready to deploy the new VNF
+
+ // NOTE: For this section, heatTemplate is used for both HEAT templates and Cloudify blueprints.
+ // In final implementation (post-POC), the template object would either be generic or there would
+ // be a separate DB Table/Object for Blueprints.
+
+ try {
+ // NOTE: The template is fixed for the VF Module. The environment is part of the customization.
+ String heatTemplateArtifactUuid = null;
+ String heatEnvironmentArtifactUuid = null;
+
+ if (isVolumeRequest) {
+ heatTemplateArtifactUuid = vf.getVolHeatTemplateArtifactUUId();
+ heatEnvironmentArtifactUuid = vfmc.getVolEnvironmentArtifactUuid();
+ } else {
+ heatTemplateArtifactUuid = vf.getHeatTemplateArtifactUUId();
+ heatEnvironmentArtifactUuid = vfmc.getHeatEnvironmentArtifactUuid();
+ }
+
+ if (heatTemplateArtifactUuid == null || heatTemplateArtifactUuid.equals("")) {
+ String error = "Create: No Heat Template ID defined in catalog database for " + vfModuleType + ", reqType=" + requestType;
+ LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Template ID", vfModuleType, "Cloudify", "", MsoLogger.ErrorCode.DataError, "Create: No Heat Template ID defined in catalog database");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
+ alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error);
+ throw new VnfException(error, MsoExceptionCategory.INTERNAL);
+ }
+
+ HeatTemplate heatTemplate = db.getHeatTemplateByArtifactUuidRegularQuery(heatTemplateArtifactUuid);
+
+ if (heatTemplate == null) {
+ String error = "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid;
+ LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM,
+ "Heat Template ID",
+ String.valueOf(heatTemplateArtifactUuid), "Cloudify", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
+ alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error);
+ throw new VnfException(error, MsoExceptionCategory.INTERNAL);
+ }
+ LOGGER.debug("Got HEAT Template record from DB");
+
+ // Next get the Environment record. This is optional.
+ HeatEnvironment heatEnvironment = null;
+ if (heatEnvironmentArtifactUuid != null && !heatEnvironmentArtifactUuid.equals(""))
+ {
+ heatEnvironment = db.getHeatEnvironmentByArtifactUuid(heatEnvironmentArtifactUuid);
+ if (heatEnvironment == null) {
+ String error = "Create VFModule: undefined Heat Environment. VFModule=" + vfModuleType
+ + ", Environment ID="
+ + heatEnvironmentArtifactUuid;
+ LOGGER.error (MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Environment ID", String.valueOf(heatEnvironmentArtifactUuid), "Cloudify", "getEnvironment", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: undefined Heat Environment");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error);
+ // Alarm on this error, configuration must be fixed
+ alarmLogger.sendAlarm (MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error);
+
+ throw new VnfException (error, MsoExceptionCategory.INTERNAL);
+ }
+ LOGGER.debug ("Got Heat Environment from DB");
+ } else {
+ LOGGER.debug ("no environment parameter found for this Type " + vfModuleType);
+ }
+
+
+ // NOTE: Logic to support nested templates and "get_file" attachments was removed from
+ // Cloudify-based adapter. Assumption is that the actual blueprints and associated
+ // artifacts have been pre-loaded to Cloudify. If that changes, logic will need
+ // to be added in to dynamically build and deploy the blueprint (with all associated
+ // artifacts required for the CSAR/ZIP) before starting the actual orchestration.
+
+
+ // All variables converted to their native object types
+ HashMap<String, Object> goldenInputs = new HashMap<String,Object>();
+ List<String> extraInputs = new ArrayList<String>();
+
+ // NOTE: SKIP THIS FOR CLOUDIFY for now. Just use what was passed in.
+ // This whole section needs to be rewritten.
+ Boolean skipInputChecks = false;
+
+ if (skipInputChecks) {
+ goldenInputs = new HashMap<String,Object>();
+ for (String key : inputs.keySet()) {
+ goldenInputs.put(key, inputs.get(key));
+ }
+ }
+ else {
+ // Build maps for the parameters (including aliases) to simplify checks
+ HashMap<String, HeatTemplateParam> params = new HashMap<String, HeatTemplateParam>();
+
+ Set<HeatTemplateParam> paramSet = heatTemplate.getParameters();
+ LOGGER.debug("paramSet has " + paramSet.size() + " entries");
+
+ for (HeatTemplateParam htp : paramSet) {
+ params.put(htp.getParamName(), htp);
+
+ // Include aliases.
+ String alias = htp.getParamAlias();
+ if (alias != null && !alias.equals("") && !params.containsKey(alias)) {
+ params.put(alias, htp);
+ }
+ }
+
+ // First, convert all inputs to their "template" type
+ for (String key : inputs.keySet()) {
+ if (params.containsKey(key)) {
+ Object value = cloudify.convertInputValue(inputs.get(key), params.get(key));
+ if (value != null) {
+ goldenInputs.put(key, value);
+ }
+ else {
+ LOGGER.debug("Failed to convert input " + key + "='" + inputs.get(key) + "' to " + params.get(key).getParamType());
+ }
+ } else {
+ extraInputs.add(key);
+ }
+ }
+
+ if (!extraInputs.isEmpty()) {
+ LOGGER.debug("Ignoring extra inputs: " + extraInputs);
+ }
+
+ // Next add in Volume Group Outputs if there are any. Copy directly without conversions.
+ if (volumeGroupOutputs != null && !volumeGroupOutputs.isEmpty()) {
+ for (String key : volumeGroupOutputs.keySet()) {
+ if (params.containsKey(key) && !goldenInputs.containsKey(key)) {
+ goldenInputs.put(key, volumeGroupOutputs.get(key));
+ }
+ }
+ }
+
+ // Next add in Base Module Outputs if there are any. Copy directly without conversions.
+ if (baseModuleOutputs != null && !baseModuleOutputs.isEmpty()) {
+ for (String key : baseModuleOutputs.keySet()) {
+ if (params.containsKey(key) && !goldenInputs.containsKey(key)) {
+ goldenInputs.put(key, baseModuleOutputs.get(key));
+ }
+ }
+ }
+
+ // Last, add in values from the "environment" file.
+ // These are added to the inputs, since Cloudify doesn't pass an environment file like Heat.
+ if (heatEnvironment != null)
+ {
+ // TODO: This may take a different form for Cloudify, but for now process it
+ // with Heat environment file syntax
+ StringBuilder sb = new StringBuilder(heatEnvironment.getEnvironment());
+ MsoHeatEnvironmentEntry mhee = new MsoHeatEnvironmentEntry (sb);
+
+ if (mhee.getParameters() != null) {
+ for (MsoHeatEnvironmentParameter envParam : mhee.getParameters()) {
+ // If this is a template input, copy to golden inputs
+ String envKey = envParam.getName();
+ if (params.containsKey(envKey) && !goldenInputs.containsKey(envKey)) {
+ Object value = cloudify.convertInputValue(envParam.getValue(), params.get(envKey));
+ if (value != null) {
+ goldenInputs.put(envKey, value);
+ }
+ else {
+ LOGGER.debug("Failed to convert environment parameter " + envKey + "='" + envParam.getValue() + "' to " + params.get(envKey).getParamType());
+ }
+ }
+ }
+ }
+ }
+ else {
+ LOGGER.debug("NO ENVIRONMENT for this entry");
+ }
+
+ this.sendMapToDebug(goldenInputs, "Final inputs sent to Cloudify");
+
+
+ // Check that required parameters have been supplied from any of the sources
+ String missingParams = null;
+ boolean checkRequiredParameters = true;
+ try {
+ String propertyString = msoPropertiesFactory.getMsoJavaProperties (MSO_PROP_VNF_ADAPTER)
+ .getProperty (MsoVnfCloudifyAdapterImpl.CHECK_REQD_PARAMS,null);
+ if ("false".equalsIgnoreCase (propertyString) || "n".equalsIgnoreCase (propertyString)) {
+ checkRequiredParameters = false;
+ LOGGER.debug ("CheckRequiredParameters is FALSE. Will still check but then skip blocking..."
+ + MsoVnfCloudifyAdapterImpl.CHECK_REQD_PARAMS);
+ }
+ } catch (Exception e) {
+ // No problem - default is true
+ LOGGER.debug ("An exception occured trying to get property " + MsoVnfCloudifyAdapterImpl.CHECK_REQD_PARAMS, e);
+ }
+
+
+ for (HeatTemplateParam parm : heatTemplate.getParameters ()) {
+ if (parm.isRequired () && (!goldenInputs.containsKey (parm.getParamName ()))) {
+ LOGGER.debug ("adding to missing parameters list: " + parm.getParamName ());
+ if (missingParams == null) {
+ missingParams = parm.getParamName ();
+ } else {
+ missingParams += "," + parm.getParamName ();
+ }
+ }
+ }
+
+ if (missingParams != null) {
+ if (checkRequiredParameters) {
+ // Problem - missing one or more required parameters
+ String error = "Create VFModule: Missing Required inputs: " + missingParams;
+ LOGGER.error (MessageEnum.RA_MISSING_PARAM, missingParams, "Cloudify", "", MsoLogger.ErrorCode.DataError, "Create VFModule: Missing Required inputs");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, error);
+ throw new VnfException (error, MsoExceptionCategory.USERDATA);
+ } else {
+ LOGGER.debug ("found missing parameters [" + missingParams + "] - but checkRequiredParameters is false - will not block");
+ }
+ } else {
+ LOGGER.debug ("No missing parameters found - ok to proceed");
+ }
+
+ } // NOTE: END PARAMETER CHECKING
+
+ // Ready to deploy the VF Module.
+ // First step - make sure the blueprint is loaded into Cloudify.
+
+ String blueprintName = heatTemplate.getTemplateName();
+ String blueprint = heatTemplate.getTemplateBody();
+
+ // Use the main blueprint name as the blueprint ID (strip yaml extensions).
+ String blueprintId = blueprintName;
+ if (blueprintId.endsWith(".yaml"))
+ blueprintId = blueprintId.substring(0,blueprintId.lastIndexOf(".yaml"));
+
+ try {
+ if (! cloudify.isBlueprintLoaded (cloudSiteId, blueprintId)) {
+ LOGGER.debug ("Blueprint " + blueprintId + " is not loaded. Will upload it now.");
+
+ Map<String,byte[]> blueprintFiles = new HashMap<String,byte[]>();
+
+ blueprintFiles.put(blueprintName, blueprint.getBytes());
+
+ // TODO: Implement nested blueprint logic based on Cloudify structures.
+ // For now, just use the Heat structures.
+ // The query returns a map of String->Object, where the map keys provide one layer of
+ // indirection from the Heat template names. For this case, assume the map key matches
+ // the nested blueprint name.
+ Map <String, Object> nestedBlueprints = db.getNestedTemplates (heatTemplate.getArtifactUuid());
+ if (nestedBlueprints != null) {
+ for (String nestedBlueprintName: nestedBlueprints.keySet()) {
+ String nestedBlueprint = (String) nestedBlueprints.get(nestedBlueprintName);
+ blueprintFiles.put(nestedBlueprintName, nestedBlueprint.getBytes());
+ }
+ }
+
+ // TODO: Implement file artifact logic based on Cloudify structures.
+ // For now, just use the Heat structures.
+ Map<String, HeatFiles> heatFiles = db.getHeatFilesForVfModule (vf.getModelUUID());
+ if (heatFiles != null) {
+ for (String heatFileName: heatFiles.keySet()) {
+ String heatFile = heatFiles.get(heatFileName).getFileBody();
+ blueprintFiles.put(heatFileName, heatFile.getBytes());
+ }
+ }
+
+ // Upload the blueprint package
+ cloudify.uploadBlueprint(cloudSiteId, blueprintId, blueprintName, blueprintFiles, false);
+
+ }
+ }
+ catch (MsoException me) {
+ me.addContext ("CreateVFModule");
+ String error = "Create VF Module: Upload blueprint failed. Blueprint=" + blueprintName + ": " + me;
+ LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "Cloudify", "", MsoLogger.ErrorCode.DataError, "MsoException - uploadBlueprint", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new VnfException (me);
+
+ }
+
+ // Ignore MsoTenantNotFound and MsoStackAlreadyExists exceptions
+ // because we already checked for those.
+ long createDeploymentStarttime = System.currentTimeMillis ();
+ try {
+ // KLUDGE - Cloudify requires Tenant Name for Openstack. We have the ID.
+ // Go directly to Keystone until APIs could be updated to supply the name.
+ MsoKeystoneUtils keystone = new MsoKeystoneUtils(MSO_PROP_VNF_ADAPTER);
+ MsoTenant msoTenant = keystone.queryTenant(tenantId, cloudSiteId);
+ String tenantName = (msoTenant != null? msoTenant.getTenantName() : tenantId);
+
+ if (backout == null) {
+ backout = true;
+ }
+ cloudifyDeployment = cloudify.createAndInstallDeployment (cloudSiteId,
+ tenantName,
+ vfModuleName,
+ blueprintId,
+ goldenInputs,
+ true,
+ heatTemplate.getTimeoutMinutes (),
+ backout.booleanValue());
+
+ LOGGER.recordMetricEvent (createDeploymentStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Cloudify", "Cloudify", "CreateDeployment", vfModuleName);
+ } catch (MsoException me) {
+ me.addContext ("CreateVFModule");
+ String error = "Create VF Module " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + me;
+ LOGGER.recordMetricEvent (createDeploymentStarttime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "Cloudify", "CreateDeployment", vfModuleName);
+ LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "Cloudify", "", MsoLogger.ErrorCode.DataError, "MsoException - createDeployment", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new VnfException (me);
+ } catch (NullPointerException npe) {
+ String error = "Create VFModule " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + npe;
+ LOGGER.recordMetricEvent (createDeploymentStarttime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "Cloudify", "CreateDeployment", vfModuleName);
+ LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "Cloudify", "", MsoLogger.ErrorCode.DataError, "NullPointerException - createDeployment", npe);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ LOGGER.debug("NULL POINTER EXCEPTION at cloudify.createAndInstallDeployment");
+ //npe.addContext ("CreateVNF");
+ throw new VnfException ("NullPointerException during cloudify.createAndInstallDeployment");
+ } catch (Exception e) {
+ LOGGER.recordMetricEvent (createDeploymentStarttime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while creating deployment with Cloudify", "Cloudify", "CreateDeployment", vfModuleName);
+ LOGGER.debug("unhandled exception at cloudify.createAndInstallDeployment");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while creating deployment with Cloudify");
+ throw new VnfException("Exception during cloudify.createAndInstallDeployment! " + e.getMessage());
+ }
+ } catch (Exception e) {
+ LOGGER.debug("unhandled exception in create VF");
+ throw new VnfException("Exception during create VF " + e.getMessage());
+
+ } finally {
+ // Make sure DB session is closed
+ db.close ();
+ }
+
+ // Reach this point if create is successful.
+ // Populate remaining rollback info and response parameters.
+ vfRollback.setVnfCreated (true);
+ vfRollback.setVnfId (cloudifyDeployment.getId());
+ vnfId.value = cloudifyDeployment.getId();
+ outputs.value = copyStringOutputs (cloudifyDeployment.getOutputs ());
+
+ rollback.value = vfRollback;
+
+ LOGGER.debug ("VF Module " + vfModuleName + " successfully created");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module");
+ return;
+ }
+
+ public void deleteVfModule (String cloudSiteId,
+ String tenantId,
+ String vnfName,
+ MsoRequest msoRequest,
+ Holder <Map <String, String>> outputs) throws VnfException {
+ MsoLogger.setLogContext (msoRequest);
+ MsoLogger.setServiceName ("DeleteVf");
+ LOGGER.debug ("Deleting VF " + vnfName + " in " + cloudSiteId + "/" + tenantId);
+ // Will capture execution time for metrics
+ long startTime = System.currentTimeMillis ();
+
+ MsoCloudifyUtils cloudify = new MsoCloudifyUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory);
+
+ // 1702 capture the output parameters on a delete
+ // so we'll need to query first
+ DeploymentInfo deployment = null;
+ try {
+ deployment = cloudify.queryDeployment(cloudSiteId, tenantId, vnfName);
+ } catch (MsoException me) {
+ // Failed to query the deployment. Convert to a generic VnfException
+ me.addContext ("DeleteVFModule");
+ String error = "Delete VFModule: Query to get outputs: " + vnfName + " in " + cloudSiteId + "/" + tenantId + ": " + me;
+ LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "Cloudify", "QueryDeployment", null);
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "Cloudify", "QueryDeployment", MsoLogger.ErrorCode.DataError, "Exception - QueryDeployment", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new VnfException (me);
+ }
+ // call method which handles the conversion from Map<String,Object> to Map<String,String> for our expected Object types
+ outputs.value = convertMapStringObjectToStringString(deployment.getOutputs());
+
+ // Use the MsoHeatUtils to delete the stack. Set the polling flag to true.
+ // The possible outcomes of deleteStack are a StackInfo object with status
+ // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException
+ // could be thrown.
+ long subStartTime = System.currentTimeMillis ();
+ try {
+ cloudify.uninstallAndDeleteDeployment(cloudSiteId, tenantId, vnfName, 5);
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from DeleteDeployment", "Cloudify", "DeleteDeployment", vnfName);
+ } catch (MsoException me) {
+ me.addContext ("DeleteVfModule");
+ // Convert to a generic VnfException
+ String error = "Delete VF: " + vnfName + " in " + cloudSiteId + "/" + tenantId + ": " + me;
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "DeleteDeployment", "DeleteDeployment", vnfName);
+ LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vnfName, cloudSiteId, tenantId, "DeleteDeployment", "DeleteDeployment", MsoLogger.ErrorCode.DataError, "Exception - DeleteDeployment: " + me.getMessage());
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new VnfException (me);
+ }
+
+ // On success, nothing is returned.
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully delete VF");
+ return;
+ }
+
+ // TODO: Should Update be supported for Cloudify? What would this look like?
+ @Override
+ public void updateVfModule (String cloudSiteId,
+ String tenantId,
+ String vnfType,
+ String vnfVersion,
+ String vnfName,
+ String requestType,
+ String volumeGroupHeatStackId,
+ String baseVfHeatStackId,
+ String vfModuleStackId,
+ String modelCustomizationUuid,
+ Map <String, String> inputs,
+ MsoRequest msoRequest,
+ Holder <Map <String, String>> outputs,
+ Holder <VnfRollback> rollback) throws VnfException
+ {
+ // This operation is not currently supported for Cloudify-orchestrated VF Modules.
+ LOGGER.debug ("Update VF Module command attempted but not supported");
+ throw new VnfException ("UpdateVfModule: Unsupported command", MsoExceptionCategory.USERDATA);
+ }
+
+}
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRest.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRest.java
index c438e7b821..d393bea713 100644
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRest.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRest.java
@@ -618,4 +618,4 @@ public class VnfAdapterRest {
LOGGER.debug ("RollbackVfModulesTask exit: code=" + getStatusCode() + ", resp="+ getResponse());
}
}
-}
+} \ No newline at end of file
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestUtils.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestUtils.java
new file mode 100644
index 0000000000..f7302c0bf5
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestUtils.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.vnf;
+
+import java.util.Optional;
+
+import org.openecomp.mso.cloud.CloudConfigFactory;
+import org.openecomp.mso.cloud.CloudSite;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+
+public class VnfAdapterRestUtils
+{
+ private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+ private static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
+ private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+
+ /*
+ * Choose which implementation of VNF Adapter to use, based on the orchestration mode.
+ * Currently, the two supported orchestrators are HEAT and CLOUDIFY.
+ */
+ public static MsoVnfAdapter getVnfAdapterImpl (String mode, String cloudSiteId)
+ {
+ // First, determine the orchestration mode to use.
+ // If was explicitly provided as a parameter, use that. Else if specified for the
+ // cloudsite, use that. Otherwise, the default is the (original) HEAT-based impl.
+
+ LOGGER.debug ("Entered GetVnfAdapterImpl: mode=" + mode + ", cloudSite=" + cloudSiteId);
+
+ if (mode == null) {
+ // Didn't get an explicit mode type requested.
+ // Use the CloudSite to determine which Impl to use, based on whether the target cloutSite
+ // has a CloudifyManager assigned to it
+ Optional<CloudSite> cloudSite = cloudConfigFactory.getCloudConfig().getCloudSite(cloudSiteId);
+ if (cloudSite.isPresent()) {
+ LOGGER.debug("Got CloudSite: " + cloudSite.toString());
+ if (cloudSite.get().getCloudifyManager() != null) {
+ mode = "CLOUDIFY";
+ } else {
+ mode = "HEAT";
+ }
+ }
+ }
+
+ LOGGER.debug ("GetVnfAdapterImpl: mode=" + mode);
+
+ MsoVnfAdapter vnfAdapter = null;
+
+ // TODO: Make this more dynamic (e.g. Service Loader)
+ if ("CLOUDIFY".equalsIgnoreCase(mode)) {
+ LOGGER.debug ("GetVnfAdapterImpl: Return Cloudify Adapter");
+ vnfAdapter = new MsoVnfCloudifyAdapterImpl (msoPropertiesFactory, cloudConfigFactory);;
+ }
+ else if ("HEAT".equalsIgnoreCase(mode)) {
+ LOGGER.debug ("GetVnfAdapterImpl: Return Heat Adapter");
+ vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory, cloudConfigFactory);
+ }
+ else {
+ // Don't expect this, but default is the HEAT adapter
+ LOGGER.debug ("GetVnfAdapterImpl: Return Default (Heat) Adapter");
+ vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory, cloudConfigFactory);
+ }
+
+ return vnfAdapter;
+ }
+
+}
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestV2.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestV2.java
new file mode 100644
index 0000000000..5e17e9c015
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestV2.java
@@ -0,0 +1,629 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.vnf;
+
+
+import java.util.Map;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.GenericEntity;
+import javax.ws.rs.core.MediaType;
+import javax.xml.ws.Holder;
+
+import org.apache.http.HttpStatus;
+
+import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
+import org.openecomp.mso.entity.MsoRequest;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.openstack.beans.VnfStatus;
+import org.openecomp.mso.openstack.beans.VnfRollback;
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+import org.openecomp.mso.adapters.vnfrest.*;
+
+/**
+ * This class services calls to the REST interface for VF Modules (http://host:port/vnfs/rest/v2/vnfs)
+ * Both XML and JSON can be produced/consumed. Set Accept: and Content-Type: headers appropriately. XML is the default.
+ * For testing, call with cloudSiteId = ___TESTING___
+ * To test exceptions, also set tenantId = ___TESTING___
+ *
+ * V2 incorporates run-time selection of sub-orchestrator implementation (Heat or Cloudify)
+ * based on the target cloud.
+ */
+@Path("/v2/vnfs")
+public class VnfAdapterRestV2 {
+ private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+ private static final String TESTING_KEYWORD = "___TESTING___";
+ //TODO Logging, SkipAAI, CREATED flags, Integrate with BPEL, Auth,
+
+ @HEAD
+ @GET
+ @Path("/healthcheck")
+ @Produces(MediaType.TEXT_HTML)
+ public Response healthcheck () {
+ String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>";
+ return Response.ok().entity(CHECK_HTML).build();
+ }
+
+ /*
+ * URL:http://localhost:8080/vnfs/rest/v2/vnfs/<aaivnfid>/vf-modules/<aaimodid>
+ * REQUEST:
+ * {"deleteVfModuleRequest":
+ {"cloudSiteId": "DAN",
+ "tenantId": "214b428a1f554c02935e66330f6a5409",
+ "vnfId": "somevnfid",
+ "vfModuleId": "somemodid",
+ "vfModuleStackId": "4e567676-e266-4594-a3a6-131c8a2baf73",
+ "messageId": "ra.1",
+ "notificationUrl": "http://localhost:8089/vnfmock",
+ "skipAAI": true,
+ "msoRequest": {
+ "requestId": "ra1",
+ "serviceInstanceId": "sa1"
+ }}
+ }
+ */
+ @DELETE
+ @Path("{aaiVnfId}/vf-modules/{aaiVfModuleId}")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response deleteVfModule (
+ @PathParam("aaiVnfId") String aaiVnfId,
+ @PathParam("aaiVfModuleId") String aaiVfModuleId,
+ @QueryParam("mode") String mode,
+ final DeleteVfModuleRequest req)
+ {
+ LOGGER.debug("Delete VfModule enter: " + req.toJsonString());
+ if (aaiVnfId == null || !aaiVnfId.equals(req.getVnfId())) {
+ LOGGER.debug("Req rejected - aaiVnfId not provided or doesn't match URL");
+ return Response
+ .status(HttpStatus.SC_BAD_REQUEST)
+ .type(MediaType.TEXT_PLAIN)
+ .entity("vnfid in URL does not match content")
+ .build();
+ }
+ if (aaiVfModuleId == null || !aaiVfModuleId.equals(req.getVfModuleId())) {
+ LOGGER.debug("Req rejected - aaiVfModuleId not provided or doesn't match URL");
+ return Response
+ .status(HttpStatus.SC_BAD_REQUEST)
+ .type(MediaType.TEXT_PLAIN)
+ .entity("vfModuleId in URL does not match content")
+ .build();
+ }
+
+ DeleteVfModuleTask task = new DeleteVfModuleTask(req, mode);
+ if (req.isSynchronous()) {
+ // This is a synchronous request
+ task.run();
+ return Response
+ .status(task.getStatusCode())
+ .entity(task.getGenericEntityResponse())
+ .build();
+ } else {
+ // This is an asynchronous request
+ try {
+ Thread t1 = new Thread(task);
+ t1.start();
+ } catch (Exception e) {
+ // problem handling delete, send generic failure as sync resp to caller
+ LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, "", "deleteVfModule", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in deleteVfModule", e);
+ return Response.serverError().build();
+ }
+ // send sync response (ACK) to caller
+ LOGGER.debug ("deleteVNFVolumes exit");
+ return Response.status(HttpStatus.SC_ACCEPTED).build();
+ }
+ }
+
+ public class DeleteVfModuleTask implements Runnable {
+ private final DeleteVfModuleRequest req;
+ private DeleteVfModuleResponse response = null;
+ private VfModuleExceptionResponse eresp = null;
+ private boolean sendxml;
+ private String mode;
+
+ public DeleteVfModuleTask(DeleteVfModuleRequest req, String mode) {
+ this.req = req;
+ this.sendxml = true; // can be set with a field or header later
+ this.mode = mode;
+ }
+ public int getStatusCode() {
+ return (response != null) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST;
+ }
+ public Object getGenericEntityResponse() {
+ return (response != null)
+ ? new GenericEntity<DeleteVfModuleResponse>(response) {}
+ : new GenericEntity<VfModuleExceptionResponse>(eresp) {};
+ }
+ private String getResponse() {
+ if (response != null) {
+ return sendxml ? response.toXmlString() : response.toJsonString();
+ } else {
+ return sendxml ? eresp.toXmlString() : eresp.toJsonString();
+ }
+ }
+
+ @Override
+ public void run() {
+ try {
+ String cloudsite = req.getCloudSiteId();
+ Holder<Map<String, String>> outputs = new Holder <Map <String, String>> ();
+ if (cloudsite != null && !cloudsite.equals(TESTING_KEYWORD)) {
+ //vnfAdapter.deleteVnf (req.getCloudSiteId(), req.getTenantId(), req.getVfModuleStackId(), req.getMsoRequest());
+ // Support different Adapter Implementations
+ MsoVnfAdapter adapter = VnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudsite);
+ adapter.deleteVfModule (req.getCloudSiteId(), req.getTenantId(), req.getVfModuleStackId(), req.getMsoRequest(), outputs);
+ }
+ response = new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), Boolean.TRUE, req.getMessageId(), outputs.value);
+ } catch (VnfException e) {
+ LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "VnfException - Delete VNF Module", e);
+ eresp = new VfModuleExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, Boolean.TRUE, req.getMessageId());
+ }
+ if (!req.isSynchronous()) {
+ BpelRestClient bpelClient = new BpelRestClient();
+ bpelClient.bpelPost(getResponse(), req.getNotificationUrl(), sendxml);
+ }
+ LOGGER.debug ("Delete vfModule exit: code=" + getStatusCode() + ", resp="+ getResponse());
+ }
+ }
+
+ /*
+ * URL:http://localhost:8080/vnfs/rest/v2/vnfs/<aaiVnfId>/vf-modules/<aaiVfModuleId>?cloudSiteId=DAN&tenantId=vfModule?&skipAAI=TRUE&msoRequest.requestId=ra1&msoRequest.serviceInstanceId=si1&vfModuleName=T2N2S1
+ * RESP:
+ * {"queryVfModuleResponse": {
+ "vfModuleId": "AvfmodId",
+ "vfModuleOutputs": {"entry": {
+ "key": "server_private_ip_1",
+ "value": "10.100.1.25"
+ }},
+ "vfModuleStackId": "RaaVnf1/abfa8a6d-feb1-40af-aea3-109403b1cf6b",
+ "vnfId": "AvnfID",
+ "vnfStatus": "ACTIVE"
+ }}
+ */
+ @GET
+ @Path("{aaiVnfId}/vf-modules/{aaiVfModuleId}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response queryVfModule(
+ @PathParam("aaiVnfId") String aaiVnfId,
+ @PathParam("aaiVfModuleId") String aaiVfModuleId,
+ @QueryParam("cloudSiteId") String cloudSiteId,
+ @QueryParam("tenantId") String tenantId,
+ @QueryParam("vfModuleName") String vfModuleName, //RAA? Id in doc
+ @QueryParam("skipAAI") Boolean skipAAI,
+ @QueryParam("msoRequest.requestId") String requestId,
+ @QueryParam("msoRequest.serviceInstanceId") String serviceInstanceId,
+ @QueryParam("mode") String mode)
+ {
+ //This request responds synchronously only
+ LOGGER.debug ("Query vfModule enter:" + vfModuleName);
+ MsoRequest msoRequest = new MsoRequest(requestId, serviceInstanceId);
+
+ try {
+ int respStatus = HttpStatus.SC_OK;
+ QueryVfModuleResponse qryResp = new QueryVfModuleResponse(aaiVnfId, aaiVfModuleId, null, null, null);
+ Holder<Boolean> vnfExists = new Holder<Boolean>();
+ Holder<String> vfModuleId = new Holder<String>();
+ Holder<VnfStatus> status = new Holder<VnfStatus>();
+ Holder<Map<String, String>> outputs = new Holder <Map <String, String>> ();
+
+ // Support different Adapter Implementations
+ MsoVnfAdapter adapter = VnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudSiteId);
+ adapter.queryVnf (cloudSiteId, tenantId, vfModuleName, msoRequest, vnfExists, vfModuleId, status, outputs);
+
+ if (!vnfExists.value) {
+ LOGGER.debug ("vfModule not found");
+ respStatus = HttpStatus.SC_NOT_FOUND;
+ } else {
+ LOGGER.debug ("vfModule found" + vfModuleId.value + ", status=" + status.value);
+ qryResp.setVfModuleId(vfModuleId.value);
+ qryResp.setVnfStatus(status.value);
+ qryResp.setVfModuleOutputs(outputs.value);
+ }
+ LOGGER.debug ("Query vfModule exit");
+ return Response
+ .status(respStatus)
+ .entity(new GenericEntity<QueryVfModuleResponse>(qryResp) {})
+ .build();
+ } catch (VnfException e) {
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, "", "queryVfModule", MsoLogger.ErrorCode.BusinessProcesssError, "VnfException - queryVfModule", e);
+ VfModuleExceptionResponse excResp = new VfModuleExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, Boolean.FALSE, null);
+ return Response
+ .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
+ .entity(new GenericEntity<VfModuleExceptionResponse>(excResp) {})
+ .build();
+ }
+ }
+
+ /*URL: http://localhost:8080/vnfs/rest/v2/vnfs/<aaivnfid>/vf-modules
+ *REQUEST:
+ * {"createVfModuleRequest":
+ {"cloudSiteId": "DAN",
+ "tenantId": "214b428a1f554c02935e66330f6a5409",
+ "vnfId": "somevnfid",
+ "vfModuleId": "somemodid",
+ "vfModuleName": "RaaVnf1",
+ "vnfType": "ApacheVnf",
+ "vfModuleParams": {"entry": [
+ {"key": "network_id",
+ "value": "59ed7b41-2983-413f-ba93-e7d437433916"},
+ {"key": "subnet_id",
+ "value": "086c9298-5c57-49b7-bb2b-6fd5730c5d92"},
+ {"key": "server_name_0",
+ "value": "RaaVnf1"}
+ ]},
+ "failIfExists": true,
+ "messageId": "ra.1",
+ "notificationUrl": "http://localhost:8089/vnfmock",
+ "skipAAI": true,
+ "msoRequest": {
+ "requestId": "ra1",
+ "serviceInstanceId": "sa1"
+ }}
+ }
+ */
+ @POST
+ @Path("{aaiVnfId}/vf-modules")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response createVfModule(
+ @PathParam("aaiVnfId") String aaiVnfId,
+ @QueryParam("mode") String mode,
+ final CreateVfModuleRequest req)
+ {
+ LOGGER.debug("Create VfModule enter inside VnfAdapterRest: " + req.toJsonString());
+ if (aaiVnfId == null || !aaiVnfId.equals(req.getVnfId())) {
+ LOGGER.debug("Req rejected - aaiVnfId not provided or doesn't match URL");
+ return Response
+ .status(HttpStatus.SC_BAD_REQUEST)
+ .type(MediaType.TEXT_PLAIN)
+ .entity("vnfid in URL does not match content")
+ .build();
+ }
+
+ CreateVfModuleTask task = new CreateVfModuleTask(req, mode);
+ if (req.isSynchronous()) {
+ // This is a synchronous request
+ task.run();
+ return Response
+ .status(task.getStatusCode())
+ .entity(task.getGenericEntityResponse())
+ .build();
+ } else {
+ // This is an asynchronous request
+ try {
+ Thread t1 = new Thread(task);
+ t1.start();
+ } catch (Exception e) {
+ // problem handling create, send generic failure as sync resp to caller
+ LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, "", "createVfModule", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - createVfModule", e);
+ return Response.serverError().build();
+ }
+ // send sync response (ACK) to caller
+ LOGGER.debug ("createVfModule exit");
+ return Response.status(HttpStatus.SC_ACCEPTED).build();
+ }
+ }
+
+ public class CreateVfModuleTask implements Runnable {
+ private final CreateVfModuleRequest req;
+ private CreateVfModuleResponse response = null;
+ private VfModuleExceptionResponse eresp = null;
+ private boolean sendxml;
+ private String mode;
+
+ public CreateVfModuleTask(CreateVfModuleRequest req, String mode) {
+ this.req = req;
+ this.sendxml = true; // can be set with a field or header later
+ this.mode = mode;
+ }
+ public int getStatusCode() {
+ return (response != null) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST;
+ }
+ public Object getGenericEntityResponse() {
+ return (response != null)
+ ? new GenericEntity<CreateVfModuleResponse>(response) {}
+ : new GenericEntity<VfModuleExceptionResponse>(eresp) {};
+ }
+ private String getResponse() {
+ if (response != null) {
+ return sendxml ? response.toXmlString() : response.toJsonString();
+ } else {
+ return sendxml ? eresp.toXmlString() : eresp.toJsonString();
+ }
+ }
+
+ @Override
+ public void run() {
+ LOGGER.debug ("CreateVfModuleTask start");
+ try {
+ // Synchronous Web Service Outputs
+ Holder <String> vfModuleStackId = new Holder <String> ();
+ Holder <Map <String, String>> outputs = new Holder <Map <String, String>> ();
+ Holder <VnfRollback> vnfRollback = new Holder <VnfRollback> ();
+ String completeVnfVfModuleType = req.getVnfType() + "::" + req.getVfModuleType();
+ LOGGER.debug("completeVnfVfModuleType=" + completeVnfVfModuleType);
+
+ String cloudsiteId = req.getCloudSiteId();
+ if (cloudsiteId != null && cloudsiteId.equals(TESTING_KEYWORD)) {
+ String tenant = req.getTenantId();
+ if (tenant != null && tenant.equals(TESTING_KEYWORD)) {
+ throw new VnfException("testing.");
+ }
+ vnfRollback.value = new VnfRollback(req.getVnfId(), tenant, cloudsiteId,
+ true, false, new MsoRequest("reqid", "svcid"),
+ req.getVolumeGroupId(), req.getVolumeGroupId(), req.getRequestType(), req.getModelCustomizationUuid());
+ vfModuleStackId.value = "479D3D8B-6360-47BC-AB75-21CC91981484";
+ outputs.value = VolumeAdapterRest.testMap();
+ } else {
+ // Support different Adapter Implementations
+ MsoVnfAdapter adapter = VnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudsiteId);
+ adapter.createVfModule(req.getCloudSiteId(),
+ req.getTenantId(),
+ completeVnfVfModuleType,
+ req.getVnfVersion(),
+ req.getVfModuleName(),
+ req.getRequestType(),
+ req.getVolumeGroupStackId(),
+ req.getBaseVfModuleStackId(),
+ req.getModelCustomizationUuid(),
+ req.getVfModuleParams(),
+ req.getFailIfExists(),
+ req.getBackout(),
+ req.getMsoRequest(),
+ vfModuleStackId,
+ outputs,
+ vnfRollback);
+ }
+ VfModuleRollback modRollback = new VfModuleRollback(vnfRollback.value, req.getVfModuleId(), vfModuleStackId.value, req.getMessageId());
+ response = new CreateVfModuleResponse(req.getVnfId(), req.getVfModuleId(),
+ vfModuleStackId.value, Boolean.TRUE, outputs.value, modRollback, req.getMessageId());
+ } catch (VnfException e) {
+ eresp = new VfModuleExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, Boolean.TRUE, req.getMessageId());
+ }
+ if (!req.isSynchronous()) {
+ BpelRestClient bpelClient = new BpelRestClient();
+ bpelClient.bpelPost(getResponse(), req.getNotificationUrl(), sendxml);
+ }
+ LOGGER.debug ("CreateVfModuleTask exit: code=" + getStatusCode() + ", resp="+ getResponse());
+ }
+ }
+
+ @PUT
+ @Path("{aaiVnfId}/vf-modules/{aaiVfModuleId}")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response updateVfModule(
+ @PathParam("aaiVnfId") String aaiVnfId,
+ @PathParam("aaiVfModuleId") String aaiVfModuleId,
+ @QueryParam("mode") String mode,
+ final UpdateVfModuleRequest req)
+ {
+ LOGGER.debug("Update VfModule enter: " + req.toJsonString());
+ UpdateVfModulesTask task = new UpdateVfModulesTask(req, mode);
+ if (req.isSynchronous()) {
+ // This is a synchronous request
+ task.run();
+ return Response
+ .status(task.getStatusCode())
+ .entity(task.getGenericEntityResponse())
+ .build();
+ } else {
+ // This is an asynchronous request
+ try {
+ Thread t1 = new Thread(task);
+ t1.start();
+ } catch (Exception e) {
+ // problem handling create, send generic failure as sync resp to caller
+ LOGGER.error (MessageEnum.RA_UPDATE_VNF_ERR, "", "updateVfModule", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - updateVfModule", e);
+ return Response.serverError().build();
+ }
+ // send sync response (ACK) to caller
+ LOGGER.debug ("updateVfModules exit");
+ return Response.status(HttpStatus.SC_ACCEPTED).build();
+ }
+ }
+
+ public class UpdateVfModulesTask implements Runnable {
+ private final UpdateVfModuleRequest req;
+ private UpdateVfModuleResponse response = null;
+ private VfModuleExceptionResponse eresp = null;
+ private boolean sendxml;
+ private String mode;
+
+ public UpdateVfModulesTask(UpdateVfModuleRequest req, String mode) {
+ this.req = req;
+ this.sendxml = true; // can be set with a field or header later
+ this.mode = mode;
+ }
+ public int getStatusCode() {
+ return (response != null) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST;
+ }
+ public Object getGenericEntityResponse() {
+ return (response != null)
+ ? new GenericEntity<UpdateVfModuleResponse>(response) {}
+ : new GenericEntity<VfModuleExceptionResponse>(eresp) {};
+ }
+ private String getResponse() {
+ if (response != null) {
+ return sendxml ? response.toXmlString() : response.toJsonString();
+ } else {
+ return sendxml ? eresp.toXmlString() : eresp.toJsonString();
+ }
+ }
+ @Override
+ public void run() {
+ try {
+ //MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory, cloudConfigFactory);
+
+ // Synchronous Web Service Outputs
+ Holder <String> vfModuleStackId = new Holder <String> ();
+ Holder <Map <String, String>> outputs = new Holder <Map <String, String>> ();
+ Holder <VnfRollback> vnfRollback = new Holder <VnfRollback> ();
+ String completeVnfVfModuleType = req.getVnfType() + "::" + req.getVfModuleType();
+ LOGGER.debug("in updateVf - completeVnfVfModuleType=" + completeVnfVfModuleType);
+
+ String cloudsiteId = req.getCloudSiteId();
+
+ // Support different Adapter Implementations
+ MsoVnfAdapter adapter = VnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudsiteId);
+ adapter.updateVfModule (req.getCloudSiteId(),
+ req.getTenantId(),
+ completeVnfVfModuleType,
+ req.getVnfVersion(),
+ req.getVfModuleName(),
+ req.getRequestType(),
+ req.getVolumeGroupStackId(),
+ req.getBaseVfModuleId(),
+ req.getVfModuleStackId(),
+ req.getModelCustomizationUuid(),
+ req.getVfModuleParams(),
+ req.getMsoRequest(),
+ outputs,
+ vnfRollback);
+
+ response = new UpdateVfModuleResponse(req.getVnfId(), req.getVfModuleId(),
+ vfModuleStackId.value, outputs.value, req.getMessageId());
+ } catch (VnfException e) {
+ eresp = new VfModuleExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, Boolean.TRUE, req.getMessageId());
+ }
+ if (!req.isSynchronous()) {
+ // This is asynch, so POST response back to caller
+ BpelRestClient bpelClient = new BpelRestClient ();
+ bpelClient.bpelPost (getResponse(), req.getNotificationUrl(), sendxml);
+ }
+ LOGGER.debug ("Update VfModule exit: code=" + getStatusCode() + ", resp="+ getResponse());
+ }
+ }
+ /*
+ * URL:http://localhost:8080/vnfs/rest/v2/vnfs/<aaivnfid>/vf-modules/<aaimodid>/rollback
+ * REQUEST:
+ * {"deleteVfModuleRequest":
+ {"cloudSiteId": "DAN",
+ "tenantId": "214b428a1f554c02935e66330f6a5409",
+ "vnfId": "somevnfid",
+ "vfModuleId": "somemodid",
+ "vfModuleStackId": "4e567676-e266-4594-a3a6-131c8a2baf73",
+ "messageId": "ra.1",
+ "notificationUrl": "http://localhost:8089/vnfmock",
+ "skipAAI": true,
+ "msoRequest": {
+ "requestId": "ra1",
+ "serviceInstanceId": "sa1"
+ }}
+ }
+ */
+ @DELETE
+ @Path("{aaiVnfId}/vf-modules/{aaiVfModuleId}/rollback")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response rollbackVfModule (
+ @PathParam("aaiVnfId") String aaiVnfId,
+ @PathParam("aaiVfModuleId") String aaiVfModuleId,
+ //@QueryParam("rollback") String rollback,
+ final RollbackVfModuleRequest req)
+ {
+ LOGGER.debug("Rollback VfModule enter: " + req.toJsonString());
+ RollbackVfModulesTask task = new RollbackVfModulesTask(req);
+ if (req.isSynchronous()) {
+ // This is a synchronous request
+ task.run();
+ return Response
+ .status(task.getStatusCode())
+ .entity(task.getGenericEntityResponse())
+ .build();
+ } else {
+ // This is an asynchronous request
+ try {
+ Thread t1 = new Thread(task);
+ t1.start();
+ } catch (Exception e) {
+ // problem handling create, send generic failure as sync resp to caller
+ LOGGER.error (MessageEnum.RA_ROLLBACK_VNF_ERR, "", "rollbackVfModule", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - rollbackVfModule", e);
+ return Response.serverError().build();
+ }
+ // send sync response (ACK) to caller
+ LOGGER.debug ("rollbackVfModule exit");
+ return Response.status(HttpStatus.SC_ACCEPTED).build();
+ }
+ }
+
+ public class RollbackVfModulesTask implements Runnable {
+ private final RollbackVfModuleRequest req;
+ private RollbackVfModuleResponse response = null;
+ private VfModuleExceptionResponse eresp = null;
+ private boolean sendxml;
+
+ public RollbackVfModulesTask(RollbackVfModuleRequest req) {
+ this.req = req;
+ this.sendxml = true; // can be set with a field or header later
+ }
+ public int getStatusCode() {
+ return (response != null) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST;
+ }
+ public Object getGenericEntityResponse() {
+ return (response != null)
+ ? new GenericEntity<RollbackVfModuleResponse>(response) {}
+ : new GenericEntity<VfModuleExceptionResponse>(eresp) {};
+ }
+ private String getResponse() {
+ if (response != null) {
+ return sendxml ? response.toXmlString() : response.toJsonString();
+ } else {
+ return sendxml ? eresp.toXmlString() : eresp.toJsonString();
+ }
+ }
+ @Override
+ public void run() {
+ try {
+ VfModuleRollback vmr = req.getVfModuleRollback();
+ VnfRollback vrb = new VnfRollback(
+ vmr.getVfModuleStackId(), vmr.getTenantId(), vmr.getCloudSiteId(), true, vmr.isVfModuleCreated(),
+ vmr.getMsoRequest(), null, null, null, null);
+
+ // Support multiple adapter implementations
+ MsoVnfAdapter adapter = VnfAdapterRestUtils.getVnfAdapterImpl (vmr.getMode(), vmr.getCloudSiteId());
+ adapter.rollbackVnf (vrb);
+
+ response = new RollbackVfModuleResponse(Boolean.TRUE, req.getMessageId());
+ } catch (VnfException e) {
+ LOGGER.error (MessageEnum.RA_ROLLBACK_VNF_ERR, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - rollbackVfModule", e);
+ eresp = new VfModuleExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, false, req.getMessageId());
+ }
+ if (!req.isSynchronous()) {
+ // This is asynch, so POST response back to caller
+ BpelRestClient bpelClient = new BpelRestClient ();
+ bpelClient.bpelPost (getResponse(), req.getNotificationUrl(), sendxml);
+ }
+ LOGGER.debug ("RollbackVfModulesTask exit: code=" + getStatusCode() + ", resp="+ getResponse());
+ }
+ }
+}
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VolumeAdapterRestV2.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VolumeAdapterRestV2.java
new file mode 100644
index 0000000000..423065c021
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VolumeAdapterRestV2.java
@@ -0,0 +1,578 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.vnf;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.GenericEntity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.xml.ws.Holder;
+
+import org.apache.http.HttpStatus;
+
+import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
+import org.openecomp.mso.adapters.vnfrest.CreateVolumeGroupRequest;
+import org.openecomp.mso.adapters.vnfrest.CreateVolumeGroupResponse;
+import org.openecomp.mso.adapters.vnfrest.DeleteVolumeGroupRequest;
+import org.openecomp.mso.adapters.vnfrest.DeleteVolumeGroupResponse;
+import org.openecomp.mso.adapters.vnfrest.QueryVolumeGroupResponse;
+import org.openecomp.mso.adapters.vnfrest.RollbackVolumeGroupRequest;
+import org.openecomp.mso.adapters.vnfrest.RollbackVolumeGroupResponse;
+import org.openecomp.mso.adapters.vnfrest.UpdateVolumeGroupRequest;
+import org.openecomp.mso.adapters.vnfrest.UpdateVolumeGroupResponse;
+import org.openecomp.mso.adapters.vnfrest.VolumeGroupExceptionResponse;
+import org.openecomp.mso.adapters.vnfrest.VolumeGroupRollback;
+import org.openecomp.mso.entity.MsoRequest;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.openstack.beans.VnfRollback;
+import org.openecomp.mso.openstack.beans.VnfStatus;
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+
+/**
+ * This class services calls to the REST interface for VNF Volumes (http://host:port/vnfs/rest/v1/volume-groups)
+ * Both XML and JSON can be produced/consumed. Set Accept: and Content-Type: headers appropriately. XML is the default.
+ * For testing, call with cloudSiteId = ___TESTING___
+ * To test exceptions, also set tenantId = ___TESTING___
+ *
+ * V2 incorporates run-time selection of sub-orchestrator implementation (Heat or Cloudify)
+ * based on the target cloud.
+ */
+@Path("/v2/volume-groups")
+public class VolumeAdapterRestV2 {
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+ private static final String TESTING_KEYWORD = "___TESTING___";
+
+ @POST
+ @Path("")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response createVNFVolumes(
+ @QueryParam("mode") String mode,
+ final CreateVolumeGroupRequest req)
+ {
+ LOGGER.debug("createVNFVolumes enter: " + req.toJsonString());
+ CreateVNFVolumesTask task = new CreateVNFVolumesTask(req, mode);
+ if (req.isSynchronous()) {
+ // This is a synchronous request
+ task.run();
+ return Response
+ .status(task.getStatusCode())
+ .entity(task.getGenericEntityResponse())
+ .build();
+ } else {
+ // This is an asynchronous request
+ try {
+ Thread t1 = new Thread(task);
+ t1.start();
+ } catch (Exception e) {
+ // problem handling create, send generic failure as sync resp to caller
+ LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, "", "createVNFVolumes", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - createVNFVolumes", e);
+ return Response.serverError().build();
+ }
+ // send sync response (ACK) to caller
+ LOGGER.debug ("createVNFVolumes exit");
+ return Response.status(HttpStatus.SC_ACCEPTED).build();
+ }
+ }
+
+ public class CreateVNFVolumesTask implements Runnable {
+ private final CreateVolumeGroupRequest req;
+ private CreateVolumeGroupResponse response = null;
+ private VolumeGroupExceptionResponse eresp = null;
+ private boolean sendxml;
+ private String mode;
+
+ public CreateVNFVolumesTask(CreateVolumeGroupRequest req, String mode) {
+ this.req = req;
+ this.sendxml = true; // can be set with a field or header later
+ this.mode = mode;
+ }
+ public int getStatusCode() {
+ return (response != null) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST;
+ }
+ public Object getGenericEntityResponse() {
+ return (response != null)
+ ? new GenericEntity<CreateVolumeGroupResponse>(response) {}
+ : new GenericEntity<VolumeGroupExceptionResponse>(eresp) {};
+ }
+ private String getResponse() {
+ if (response != null) {
+ return sendxml ? response.toXmlString() : response.toJsonString();
+ } else {
+ return sendxml ? eresp.toXmlString() : eresp.toJsonString();
+ }
+ }
+ @Override
+ public void run() {
+ LOGGER.debug ("CreateVFModule VolumesTask start");
+ try {
+ // Synchronous Web Service Outputs
+ Holder<String> stackId = new Holder<>();
+ Holder<Map<String, String>> outputs = new Holder<>();
+ Holder<VnfRollback> vnfRollback = new Holder<>();
+ String completeVnfVfModuleType = req.getVnfType() + "::" + req.getVfModuleType();
+ LOGGER.debug("in createVfModuleVolumes - completeVnfVfModuleType=" + completeVnfVfModuleType);
+
+ String cloudsiteId = req.getCloudSiteId();
+ if (cloudsiteId != null && cloudsiteId.equals(TESTING_KEYWORD)) {
+ String tenant = req.getTenantId();
+ if (tenant != null && tenant.equals(TESTING_KEYWORD)) {
+ throw new VnfException("testing.");
+ }
+ stackId.value = "479D3D8B-6360-47BC-AB75-21CC91981484";
+ outputs.value = testMap();
+ } else {
+ // Support different Adapter Implementations
+ MsoVnfAdapter vnfAdapter = VnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudsiteId);
+ vnfAdapter.createVfModule(
+ req.getCloudSiteId(), //cloudSiteId,
+ req.getTenantId(), //tenantId,
+ completeVnfVfModuleType, //vnfType,
+ req.getVnfVersion(), //vnfVersion,
+ req.getVolumeGroupName(), //vnfName,
+ "VOLUME", //requestType,
+ null, //volumeGroupHeatStackId,
+ null, //baseVfHeatStackId,
+ req.getModelCustomizationUuid(),
+ req.getVolumeGroupParams(), //inputs,
+ req.getFailIfExists(), //failIfExists,
+ req.getSuppressBackout(), //backout,
+ req.getMsoRequest(), // msoRequest,
+ stackId,
+ outputs,
+ vnfRollback);
+ }
+
+ VolumeGroupRollback rb = new VolumeGroupRollback(
+ req.getVolumeGroupId(),
+ stackId.value,
+ vnfRollback.value.getVnfCreated(),
+ req.getTenantId(),
+ req.getCloudSiteId(),
+ req.getMsoRequest(),
+ req.getMessageId());
+
+ response = new CreateVolumeGroupResponse(
+ req.getVolumeGroupId(),
+ stackId.value,
+ vnfRollback.value.getVnfCreated(),
+ outputs.value,
+ rb,
+ req.getMessageId());
+ } catch (VnfException e) {
+ LOGGER.debug("Exception :",e);
+ eresp = new VolumeGroupExceptionResponse(
+ e.getMessage(), MsoExceptionCategory.INTERNAL, true, req.getMessageId());
+ }
+ if (!req.isSynchronous()) {
+ // This is asynch, so POST response back to caller
+ BpelRestClient bpelClient = new BpelRestClient();
+ bpelClient.bpelPost(getResponse(), req.getNotificationUrl(), sendxml);
+ }
+ LOGGER.debug ("CreateVFModule VolumesTask exit: code=" + getStatusCode() + ", resp="+ getResponse());
+ }
+ }
+
+ @DELETE
+ @Path("{aaiVolumeGroupId}")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response deleteVNFVolumes(
+ @PathParam("aaiVolumeGroupId") String aaiVolumeGroupId,
+ @QueryParam("mode") String mode,
+ final DeleteVolumeGroupRequest req
+ )
+ {
+ LOGGER.debug("deleteVNFVolumes enter: " + req.toJsonString());
+ if (aaiVolumeGroupId == null || !aaiVolumeGroupId.equals(req.getVolumeGroupId())) {
+ return Response
+ .status(HttpStatus.SC_BAD_REQUEST)
+ .type(MediaType.TEXT_PLAIN)
+ .entity("VolumeGroupId in URL does not match content")
+ .build();
+ }
+ DeleteVNFVolumesTask task = new DeleteVNFVolumesTask(req, mode);
+ if (req.isSynchronous()) {
+ // This is a synchronous request
+ task.run();
+ return Response
+ .status(task.getStatusCode())
+ .entity(task.getGenericEntityResponse())
+ .build();
+ } else {
+ // This is an asynchronous request
+ try {
+ Thread t1 = new Thread(task);
+ t1.start();
+ } catch (Exception e) {
+ // problem handling create, send generic failure as sync resp to caller
+ LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, "", "deleteVNFVolumes", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - deleteVNFVolumes", e);
+ return Response.serverError().build();
+ }
+ // send sync response (ACK) to caller
+ LOGGER.debug ("deleteVNFVolumes exit");
+ return Response.status(HttpStatus.SC_ACCEPTED).build();
+ }
+ }
+
+ public class DeleteVNFVolumesTask implements Runnable {
+ private final DeleteVolumeGroupRequest req;
+ private DeleteVolumeGroupResponse response = null;
+ private VolumeGroupExceptionResponse eresp = null;
+ private boolean sendxml;
+ private String mode;
+
+ public DeleteVNFVolumesTask(DeleteVolumeGroupRequest req, String mode) {
+ this.req = req;
+ this.sendxml = true; // can be set with a field or header later
+ this.mode = mode;
+ }
+ public int getStatusCode() {
+ return (response != null) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST;
+ }
+ public Object getGenericEntityResponse() {
+ return (response != null)
+ ? new GenericEntity<DeleteVolumeGroupResponse>(response) {}
+ : new GenericEntity<VolumeGroupExceptionResponse>(eresp) {};
+ }
+ private String getResponse() {
+ if (response != null) {
+ return sendxml ? response.toXmlString() : response.toJsonString();
+ } else {
+ return sendxml ? eresp.toXmlString() : eresp.toJsonString();
+ }
+ }
+ @Override
+ public void run() {
+ LOGGER.debug("DeleteVNFVolumesTask start");
+ String cloudSiteId = req.getCloudSiteId();
+ try {
+ if (! cloudSiteId.equals(TESTING_KEYWORD)) {
+ // Support different Adapter Implementations
+ MsoVnfAdapter vnfAdapter = VnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudSiteId);
+ vnfAdapter.deleteVnf(req.getCloudSiteId(), req.getTenantId(), req.getVolumeGroupStackId(), req.getMsoRequest());
+ }
+ response = new DeleteVolumeGroupResponse(true, req.getMessageId());
+ } catch (VnfException e) {
+ LOGGER.debug("Exception :",e);
+ eresp = new VolumeGroupExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, true, req.getMessageId());
+ }
+ if (!req.isSynchronous()) {
+ // This is asynch, so POST response back to caller
+ BpelRestClient bpelClient = new BpelRestClient();
+ bpelClient.bpelPost(getResponse(), req.getNotificationUrl(), sendxml);
+ }
+ LOGGER.debug("DeleteVNFVolumesTask exit: code=" + getStatusCode() + ", resp="+ getResponse());
+ }
+ }
+
+ @DELETE
+ @Path("{aaiVolumeGroupId}/rollback")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response rollbackVNFVolumes(
+ @PathParam("aaiVolumeGroupId") String aaiVolumeGroupId,
+ final RollbackVolumeGroupRequest req
+ )
+ {
+ LOGGER.debug("rollbackVNFVolumes enter: " + req.toJsonString());
+ if (aaiVolumeGroupId == null || req.getVolumeGroupRollback() == null || !aaiVolumeGroupId.equals(req.getVolumeGroupRollback().getVolumeGroupId())) {
+ return Response
+ .status(HttpStatus.SC_BAD_REQUEST)
+ .type(MediaType.TEXT_PLAIN)
+ .entity("VolumeGroupId in URL does not match content")
+ .build();
+ }
+ RollbackVNFVolumesTask task = new RollbackVNFVolumesTask(req);
+ if (req.isSynchronous()) {
+ // This is a synchronous request
+ task.run();
+ return Response
+ .status(task.getStatusCode())
+ .entity(task.getGenericEntityResponse())
+ .build();
+ } else {
+ // This is an asynchronous request
+ try {
+ Thread t1 = new Thread(task);
+ t1.start();
+ } catch (Exception e) {
+ // problem handling create, send generic failure as sync resp to caller
+ LOGGER.error (MessageEnum.RA_ROLLBACK_VNF_ERR, "", "rollbackVNFVolumes", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - rollbackVNFVolumes", e);
+ return Response.serverError().build();
+ }
+ // send sync response (ACK) to caller
+ LOGGER.debug("rollbackVNFVolumes exit");
+ return Response.status(HttpStatus.SC_ACCEPTED).build();
+ }
+ }
+
+ public class RollbackVNFVolumesTask implements Runnable {
+ private final RollbackVolumeGroupRequest req;
+ private RollbackVolumeGroupResponse response = null;
+ private VolumeGroupExceptionResponse eresp = null;
+ private boolean sendxml;
+
+ public RollbackVNFVolumesTask(RollbackVolumeGroupRequest req) {
+ this.req = req;
+ this.sendxml = true; // can be set with a field or header later
+ }
+ public int getStatusCode() {
+ return (response != null) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST;
+ }
+ public Object getGenericEntityResponse() {
+ return (response != null)
+ ? new GenericEntity<RollbackVolumeGroupResponse>(response) {}
+ : new GenericEntity<VolumeGroupExceptionResponse>(eresp) {};
+ }
+ private String getResponse() {
+ if (response != null) {
+ return sendxml ? response.toXmlString() : response.toJsonString();
+ } else {
+ return sendxml ? eresp.toXmlString() : eresp.toJsonString();
+ }
+ }
+ @Override
+ public void run() {
+ LOGGER.debug("RollbackVNFVolumesTask start");
+ try {
+ VolumeGroupRollback vgr = req.getVolumeGroupRollback();
+ VnfRollback vrb = new VnfRollback(
+ vgr.getVolumeGroupStackId(), vgr.getTenantId(), vgr.getCloudSiteId(), true, true,
+ vgr.getMsoRequest(), null, null, null, null);
+
+ // Support different Adapter Implementations
+ MsoVnfAdapter vnfAdapter = VnfAdapterRestUtils.getVnfAdapterImpl(vrb.getMode(), vrb.getCloudSiteId());
+ vnfAdapter.rollbackVnf(vrb);
+ response = new RollbackVolumeGroupResponse(true, req.getMessageId());
+ } catch (VnfException e) {
+ LOGGER.debug("Exception :",e);
+ eresp = new VolumeGroupExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, true, req.getMessageId());
+ }
+ if (!req.isSynchronous()) {
+ // This is asynch, so POST response back to caller
+ BpelRestClient bpelClient = new BpelRestClient();
+ bpelClient.bpelPost(getResponse(), req.getNotificationUrl(), sendxml);
+ }
+ LOGGER.debug("RollbackVNFVolumesTask exit: code=" + getStatusCode() + ", resp="+ getResponse());
+ }
+
+ }
+
+ @PUT
+ @Path("{aaiVolumeGroupId}")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response updateVNFVolumes(
+ @PathParam("aaiVolumeGroupId") String aaiVolumeGroupId,
+ @QueryParam("mode") String mode,
+ final UpdateVolumeGroupRequest req
+ )
+ {
+ LOGGER.debug("updateVNFVolumes enter: " + req.toJsonString());
+ if (aaiVolumeGroupId == null || !aaiVolumeGroupId.equals(req.getVolumeGroupId())) {
+ return Response
+ .status(HttpStatus.SC_BAD_REQUEST)
+ .type(MediaType.TEXT_PLAIN)
+ .entity("VolumeGroupId in URL does not match content")
+ .build();
+ }
+ UpdateVNFVolumesTask task = new UpdateVNFVolumesTask(req, mode);
+ if (req.isSynchronous()) {
+ // This is a synchronous request
+ task.run();
+ return Response
+ .status(task.getStatusCode())
+ .entity(task.getGenericEntityResponse())
+ .build();
+ } else {
+ // This is an asynchronous request
+ try {
+ Thread t1 = new Thread(task);
+ t1.start();
+ } catch (Exception e) {
+ // problem handling create, send generic failure as sync resp to caller
+ LOGGER.error (MessageEnum.RA_UPDATE_VNF_ERR, "", "updateVNFVolumes", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - updateVNFVolumes", e);
+ return Response.serverError().build();
+ }
+ // send sync response (ACK) to caller
+ LOGGER.debug ("updateVNFVolumes exit");
+ return Response.status(HttpStatus.SC_ACCEPTED).build();
+ }
+ }
+
+ public class UpdateVNFVolumesTask implements Runnable {
+ private final UpdateVolumeGroupRequest req;
+ private UpdateVolumeGroupResponse response = null;
+ private VolumeGroupExceptionResponse eresp = null;
+ private boolean sendxml;
+ private String mode;
+
+ public UpdateVNFVolumesTask(UpdateVolumeGroupRequest req, String mode) {
+ this.req = req;
+ this.sendxml = true; // can be set with a field or header later
+ this.mode = mode;
+ }
+ public int getStatusCode() {
+ return (response != null) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST;
+ }
+ public Object getGenericEntityResponse() {
+ return (response != null)
+ ? new GenericEntity<UpdateVolumeGroupResponse>(response) {}
+ : new GenericEntity<VolumeGroupExceptionResponse>(eresp) {};
+ }
+ private String getResponse() {
+ if (response != null) {
+ return sendxml ? response.toXmlString() : response.toJsonString();
+ } else {
+ return sendxml ? eresp.toXmlString() : eresp.toJsonString();
+ }
+ }
+ @Override
+ public void run() {
+ LOGGER.debug("UpdateVNFVolumesTask start");
+ try {
+ @SuppressWarnings("unused")
+ Holder<Map<String, String>> outputs = new Holder<> ();
+ Holder<VnfRollback> vnfRollback = new Holder<> ();
+ String completeVnfVfModuleType = req.getVnfType() + "::" + req.getVfModuleType();
+ LOGGER.debug("in updateVfModuleVolume - completeVnfVfModuleType=" + completeVnfVfModuleType);
+
+ if (req.getCloudSiteId().equals(TESTING_KEYWORD)) {
+ outputs.value = testMap();
+ } else {
+ // Support different Adapter Implementations
+ MsoVnfAdapter vnfAdapter = VnfAdapterRestUtils.getVnfAdapterImpl(mode, req.getCloudSiteId());
+ vnfAdapter.updateVfModule (req.getCloudSiteId(),
+ req.getTenantId(),
+ //req.getVnfType(),
+ completeVnfVfModuleType,
+ req.getVnfVersion(),
+ req.getVolumeGroupStackId(),
+ "VOLUME",
+ null,
+ null,
+ req.getVolumeGroupStackId(),
+ req.getModelCustomizationUuid(),
+ req.getVolumeGroupParams(),
+ req.getMsoRequest(),
+ outputs,
+ vnfRollback);
+ }
+ response = new UpdateVolumeGroupResponse(
+ req.getVolumeGroupId(), req.getVolumeGroupStackId(),
+ outputs.value, req.getMessageId());
+ } catch (VnfException e) {
+ LOGGER.debug("Exception :",e);
+ eresp = new VolumeGroupExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, true, req.getMessageId());
+ }
+ if (!req.isSynchronous()) {
+ // This is asynch, so POST response back to caller
+ BpelRestClient bpelClient = new BpelRestClient();
+ bpelClient.bpelPost(getResponse(), req.getNotificationUrl(), sendxml);
+ }
+ LOGGER.debug("UpdateVNFVolumesTask exit: code=" + getStatusCode() + ", resp="+ getResponse());
+ }
+ }
+
+ @GET
+ @Path("{aaiVolumeGroupId}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response queryVNFVolumes(
+ @PathParam("aaiVolumeGroupId") String aaiVolumeGroupId,
+ @QueryParam("cloudSiteId") String cloudSiteId,
+ @QueryParam("tenantId") String tenantId,
+ @QueryParam("volumeGroupStackId") String volumeGroupStackId,
+ @QueryParam("skipAAI") Boolean skipAAI,
+ @QueryParam("msoRequest.requestId") String requestId,
+ @QueryParam("msoRequest.serviceInstanceId") String serviceInstanceId,
+ @QueryParam("mode") String mode
+ )
+ {
+ //This request responds synchronously only
+ LOGGER.debug ("queryVNFVolumes enter:" + aaiVolumeGroupId + " " + volumeGroupStackId);
+ MsoRequest msoRequest = new MsoRequest(requestId, serviceInstanceId);
+
+ try {
+ int respStatus = HttpStatus.SC_OK;
+ QueryVolumeGroupResponse qryResp = new QueryVolumeGroupResponse(aaiVolumeGroupId, volumeGroupStackId, null, null);
+ Holder<Boolean> vnfExists = new Holder<>();
+ Holder<String> vfModuleId = new Holder<>();
+ Holder<VnfStatus> status = new Holder<>();
+ Holder<Map<String, String>> outputs = new Holder<>();
+ if (cloudSiteId != null && cloudSiteId.equals(TESTING_KEYWORD)) {
+ if (tenantId != null && tenantId.equals(TESTING_KEYWORD)) {
+ throw new VnfException("testing.");
+ }
+ vnfExists.value = true;
+ vfModuleId.value = TESTING_KEYWORD;
+ status.value = VnfStatus.ACTIVE;
+ outputs.value = testMap();
+ } else {
+ // Support different Adapter Implementations
+ MsoVnfAdapter vnfAdapter = VnfAdapterRestUtils.getVnfAdapterImpl(mode, cloudSiteId);
+ vnfAdapter.queryVnf(cloudSiteId, tenantId, volumeGroupStackId, msoRequest, vnfExists, vfModuleId, status, outputs);
+ }
+ if (!vnfExists.value) {
+ LOGGER.debug ("VNFVolumes not found");
+ qryResp.setVolumeGroupStatus(status.value);
+ respStatus = HttpStatus.SC_NOT_FOUND;
+ } else {
+ LOGGER.debug ("VNFVolumes found " + vfModuleId.value + ", status=" + status.value);
+ qryResp.setVolumeGroupStatus(status.value);
+ qryResp.setVolumeGroupOutputs(outputs.value);
+ }
+ LOGGER.debug("Query queryVNFVolumes exit");
+ return Response
+ .status(respStatus)
+ .entity(new GenericEntity<QueryVolumeGroupResponse>(qryResp) {})
+ .build();
+ } catch (VnfException e) {
+ LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, aaiVolumeGroupId, "", "queryVNFVolumes", MsoLogger.ErrorCode.BusinessProcesssError, "VnfException - queryVNFVolumes", e);
+ VolumeGroupExceptionResponse excResp = new VolumeGroupExceptionResponse(e.getMessage(), MsoExceptionCategory.INTERNAL, Boolean.FALSE, null);
+ LOGGER.debug("Query queryVNFVolumes exit");
+ return Response
+ .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
+ .entity(new GenericEntity<VolumeGroupExceptionResponse>(excResp) {})
+ .build();
+ }
+ }
+ public static Map<String, String> testMap() {
+ Map<String, String> m = new HashMap<>();
+ m.put("mickey", "7");
+ m.put("clyde", "10");
+ m.put("wayne", "99");
+ return m;
+ }
+}
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java
index 6e06eed702..367028c68b 100755
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * OPENECOMP - MSO
+ * ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java
index 3646b292c5..7ff7df62ad 100755
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * OPENECOMP - MSO
+ * ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java
index 2118eec0a5..0b8b768bda 100755
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * OPENECOMP - MSO
+ * ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java
index 0f4611a2de..eaf7c4f14f 100755
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * OPENECOMP - MSO
+ * ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java
index d898a6547e..282b3b15cd 100644
--- a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java
+++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java
@@ -28,6 +28,7 @@ import java.util.Map;
import javax.xml.ws.Holder;
import mockit.Mock;
import mockit.MockUp;
+import org.junit.Ignore;
import org.junit.Test;
import org.openecomp.mso.adapters.vnf.MsoVnfAdapter;
import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;
@@ -38,6 +39,10 @@ import org.openecomp.mso.openstack.beans.VnfStatus;
import org.openecomp.mso.openstack.exceptions.MsoException;
import org.openecomp.mso.openstack.utils.MsoHeatUtils;
+import org.openecomp.mso.cloud.CloudConfigFactory;
+import org.openecomp.mso.properties.MsoJavaProperties;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+
public class QueryTest {
@Test
@@ -95,9 +100,27 @@ public class QueryTest {
}
@Test(expected = VnfException.class)
+ // @Ignore // 1802 merge
public void testQueryVnfWithException() throws VnfException {
{
- MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl();
+ String propFile = MsoJavaProperties.class.getClassLoader().getResource("mso.properties").getPath();
+ String cloudConfigJsonFilePath = MsoJavaProperties.class.getClassLoader().getResource("cloud_config.json").getPath();
+
+ MsoPropertiesFactory msoPropFactory = new MsoPropertiesFactory();
+ CloudConfigFactory cloudConfigFact = new CloudConfigFactory();
+ try {
+ msoPropFactory.initializeMsoProperties("MSO_PROP_VNF_ADAPTER", propFile);
+ cloudConfigFact.initializeCloudConfig(cloudConfigJsonFilePath, 1);
+ } catch (org.openecomp.mso.properties.MsoPropertiesException e) {
+ // System.err.println("!?!?!?!! mso config exception: " + e);
+ // e.printStackTrace();
+ } catch (org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound e) {
+ // System.err.println("!?!?!?!! cloud config exception: " + e);
+ // e.printStackTrace();
+ }
+
+ MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(msoPropFactory, cloudConfigFact);
+
String cloudId = "MT";
String tenantId = "MSO_Test";
String vnfName = "VNF_TEST1";
diff --git a/adapters/mso-vnf-adapter/src/test/resources/cloud_config.json b/adapters/mso-vnf-adapter/src/test/resources/cloud_config.json
new file mode 100644
index 0000000000..ff24633f32
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/test/resources/cloud_config.json
@@ -0,0 +1,94 @@
+{ "cloud_config": {
+ "identity_services":
+ {
+ "MT_KEYSTONE":
+ {
+ "identity_url": "http://localhost:5000/v2.0",
+ "mso_id": "john",
+ "mso_pass": "FD205490A48D48475607C36B9AD902BF",
+ "admin_tenant": "admin",
+ "member_role": "_member_",
+ "tenant_metadata": false,
+ "identity_server_type": "KEYSTONE",
+ "identity_authentication_type": "RACKSPACE_APIKEY"
+ },
+ "DAN_KEYSTONE":
+ {
+ "identity_url": "http://localhost:5000/v2.0",
+ "mso_id": "mockId",
+ "mso_pass": "BC59F80E38208A42ABB81ECCDD4FB3E4",
+ "admin_tenant": "service",
+ "member_role": "_member_",
+ "tenant_metadata": false,
+ "identity_server_type": "KEYSTONE",
+ "identity_authentication_type": "USERNAME_PASSWORD"
+ },
+ "MTINJVCC101_DCP":
+ {
+ "identity_url": "http://localhost:5000/v2.0",
+ "mso_id": "mockIdToo",
+ "mso_pass": "95604B9EAAC4D77D74786FAE54177206",
+ "admin_tenant": "service",
+ "member_role": "admin",
+ "tenant_metadata": true,
+ "identity_server_type": "KEYSTONE",
+ "identity_authentication_type": "USERNAME_PASSWORD"
+ },
+ "MTSNJA3DCP1":
+ {
+ "identity_url": "https://localhost:5000/v2.0",
+ "mso_id": "mockIdToo",
+ "mso_pass": "1491DE07AC9D716A7966BB8C2848F031",
+ "admin_tenant": "service",
+ "member_role": "admin",
+ "tenant_metadata": true,
+ "identity_server_type": "KEYSTONE",
+ "identity_authentication_type": "USERNAME_PASSWORD"
+ },
+ "CS_service": {}
+
+ },
+ "cloud_sites":
+ {
+ "MT":
+ {
+ "region_id": "regionOne",
+ "clli": "MT",
+ "aic_version": "2.5",
+ "identity_service_id": "MT_KEYSTONE"
+ },
+ "DAN":
+ {
+ "region_id": "RegionOne",
+ "clli": "DAN",
+ "aic_version": "2.5",
+ "identity_service_id": "DAN_KEYSTONE"
+ },
+ "MTINJVCC101":
+ {
+ "region_id": "regionTwo",
+ "clli": "MTINJVCC101",
+ "aic_version": "2.5",
+ "identity_service_id": "MTINJVCC101_DCP"
+ },
+ "MTSNJA4LCP1":
+ {
+ "region_id": "mtsnjlcp1",
+ "clli": "MTSNJA4LCP1",
+ "aic_version": "2.5",
+ "identity_service_id": "MTSNJA3DCP1"
+ },
+ "CS":
+ {
+ "region_id": "clliRegion",
+ "clli": "CS_clli",
+ "aic_version": "2.5",
+ "identity_service_id": "CS_service"
+ }
+ }
+}
+}
+
+
+
+
diff --git a/adapters/mso-vnf-adapter/src/test/resources/mso.properties b/adapters/mso-vnf-adapter/src/test/resources/mso.properties
new file mode 100644
index 0000000000..d58521f1db
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/test/resources/mso.properties
@@ -0,0 +1,27 @@
+###
+# ============LICENSE_START=======================================================
+# ECOMP MSO
+# ================================================================================
+# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
+ecomp.mso.cloud.1.cloudId=MT
+ecomp.mso.cloud.1.keystoneUrl=http://localhost:5000/v2.0
+ecomp.mso.cloud.1.msoId=John
+ecomp.mso.cloud.1.publicNetId=FD205490A48D48475607C36B9AD902BF
+ecomp.mso.cloud.1.test=1234
+ecomp.mso.cloud.1.boolean=true
+ecomp.mso.cloud.1.enum=enum1