aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java
blob: 9a64e62e57e2f0bb3c708f014914240d98c59225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
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=========================================================
 */

/**
 * This VNF Adapter implementation is based on the VDU Plugin model.  It assumes that each
 * VF Module definition in the MSO catalog is expressed via a set of template and/or file
 * artifacts that are appropriate for some specific sub-orchestrator that provides an
 * implementation of the VduPlugin interface.  This adapter handles all of the common
 * VF Module logic, including:
 * - catalog lookups for artifact retrieval
 * - parameter filtering and validation
 * - base and volume module queries
 * - rollback logic
 * - logging and error handling
 *
 * Then based on the orchestration mode of the VNF, it will invoke different VDU plug-ins
 * to perform the low level instantiations, deletions, and queries.  At this time, the
 * set of available plug-ins is hard-coded, though in the future a dynamic selection
 * is expected (e.g. via a service-provider interface).
 */
package org.onap.so.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.onap.so.adapters.vdu.CloudInfo;
import org.onap.so.adapters.vdu.VduException;
import org.onap.so.adapters.vdu.VduInstance;
import org.onap.so.adapters.vdu.VduModelInfo;
import org.onap.so.adapters.vdu.VduPlugin;
import org.onap.so.adapters.vdu.VduStateType;
import org.onap.so.adapters.vdu.VduStatus;
import org.onap.so.adapters.vdu.mapper.VfModuleCustomizationToVduMapper;
import org.onap.so.adapters.vnf.exceptions.VnfAlreadyExists;
import org.onap.so.adapters.vnf.exceptions.VnfException;
import org.onap.so.cloud.CloudConfig;
import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.cloudify.utils.MsoCloudifyUtils;
import org.onap.so.db.catalog.beans.HeatEnvironment;
import org.onap.so.db.catalog.beans.HeatTemplate;
import org.onap.so.db.catalog.beans.HeatTemplateParam;
import org.onap.so.db.catalog.beans.VfModule;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.VnfResource;
import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
import org.onap.so.db.catalog.utils.MavenLikeVersioning;
import org.onap.so.entity.MsoRequest;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoAlarmLogger;
import org.onap.so.logger.MsoLogger;
import org.onap.so.openstack.beans.VnfRollback;
import org.onap.so.openstack.beans.VnfStatus;
import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
import org.onap.so.openstack.exceptions.MsoException;
import org.onap.so.openstack.exceptions.MsoExceptionCategory;
import org.onap.so.openstack.utils.MsoHeatEnvironmentEntry;
import org.onap.so.openstack.utils.MsoHeatUtils;
import org.onap.so.openstack.utils.MsoKeystoneUtils;
import org.onap.so.openstack.utils.MsoMulticloudUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

@WebService(serviceName = "VnfAdapter", endpointInterface = "org.onap.so.adapters.vnf.MsoVnfAdapter", targetNamespace = "http://org.onap.so/vnf")
@Component
@Transactional
public class MsoVnfPluginAdapterImpl implements MsoVnfAdapter {

    private static final String MSO_CONFIGURATION_ERROR = "MsoConfigurationError";
    private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, MsoVnfPluginAdapterImpl.class);
    private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
    private static final String CHECK_REQD_PARAMS = "org.onap.so.adapters.vnf.checkRequiredParameters";
    private static final ObjectMapper JSON_MAPPER = new ObjectMapper();

    @Autowired
    protected CloudConfig cloudConfig;

    @Autowired
    private VFModuleCustomizationRepository vfModuleCustomRepo;

    @Autowired
    private Environment environment;

    @Autowired
    protected MsoKeystoneUtils keystoneUtils;

    @Autowired
    protected MsoCloudifyUtils cloudifyUtils;

    @Autowired
    protected MsoHeatUtils heatUtils;

    @Autowired
    protected MsoMulticloudUtils multicloudUtils;

	@Autowired
	protected VfModuleCustomizationToVduMapper vduMapper;

	/**
     * 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 Plugin Adapter");
    }

    /**
     * DO NOT use that constructor to instantiate this class, the msoPropertiesfactory will be NULL.
     * @see MsoVnfPluginAdapterImpl#MsoVnfAdapterImpl(MsoPropertiesFactory, CloudConfigFactory)
     */
    public MsoVnfPluginAdapterImpl() {

    }

    /**
     * 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,
                           Boolean enableBridge,
                           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.
     *
     * 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
     * @param vnfNameOrId VNF Name or ID to query
     * @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 outputs from the deployed VF Module (assigned IPs, etc)
     */
    @Override
    public void queryVnf (String cloudSiteId,
                          String tenantId,
                          String vnfNameOrId,
                          MsoRequest msoRequest,
                          Holder <Boolean> vnfExists,
                          Holder <String> vnfId,
                          Holder <VnfStatus> status,
                          Holder <Map <String, String>> outputs)
        throws VnfException
    {
        MsoLogger.setLogContext (msoRequest);
    	MsoLogger.setServiceName ("QueryVnf");
        LOGGER.debug ("Querying VNF " + vnfNameOrId + " in " + cloudSiteId + "/" + tenantId);

        // Will capture execution time for metrics
        long startTime = System.currentTimeMillis ();
        long subStartTime = System.currentTimeMillis ();

    	VduInstance vduInstance = null;
    	CloudInfo cloudInfo = new CloudInfo(cloudSiteId, tenantId, null);

        VduPlugin vduPlugin = getVduPlugin(cloudSiteId);

    	try {
    		vduInstance = vduPlugin.queryVdu (cloudInfo, vnfNameOrId);
            LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received VDU Query response", "VDU", "QueryVDU", vnfNameOrId);
    	}
    	catch (VduException e) {
            // Failed to query the VDU due to a plugin exception.
            // Convert to a generic VnfException
            e.addContext ("QueryVNF");
            String error = "Query VNF (VDU): " + vnfNameOrId + " in " + cloudSiteId + "/" + tenantId + ": " + e;
            LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVNF", vnfNameOrId);
            LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfNameOrId, cloudSiteId, tenantId, "VDU", "QueryVNF", MsoLogger.ErrorCode.DataError, "Exception - queryVDU", e);
            LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
            throw new VnfException (e);
    	}

    	if (vduInstance != null  &&  vduInstance.getStatus().getState() != VduStateType.NOTFOUND) {
            vnfExists.value = Boolean.TRUE;
            status.value = vduStatusToVnfStatus(vduInstance);
            vnfId.value = vduInstance.getVduInstanceId();
            outputs.value = copyStringOutputs (vduInstance.getOutputs ());

            LOGGER.debug ("VNF " + vnfNameOrId + " found, 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 " + vnfNameOrId + " 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", MsoLogger.getServiceName());
            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 ();
        CloudInfo cloudInfo = new CloudInfo (cloudSiteId, tenantId, null);

        String vfModuleId = rollback.getVfModuleStackId ();

        MsoLogger.setLogContext (rollback.getMsoRequest());

        LOGGER.debug ("Rolling Back VF Module " + vfModuleId + " in " + cloudSiteId + "/" + tenantId);

    	VduInstance vduInstance = null;

        // Use the VduPlugin to delete the VF Module.
        VduPlugin vduPlugin = getVduPlugin(cloudSiteId);

        long subStartTime = System.currentTimeMillis ();
        try {
        	// TODO: Get a reasonable timeout.  Use a global property, or store the creation timeout in rollback object and use that.
            vduInstance = vduPlugin.deleteVdu(cloudInfo, vfModuleId, 5);

            LOGGER.debug("Rolled back VDU instantiation: " + vduInstance.getVduInstanceId());
            LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from VDU Plugin", "VDU", "DeleteVdu", null);
        }
        catch (VduException ve) {
            // Failed to rollback the VF Module due to a plugin exception.
            // Convert to a generic VnfException
            ve.addContext ("RollbackVFModule");
            String error = "Rollback VF Module: " + vfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + ve;
            LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "DeleteVdu", null);
            LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vfModuleId, cloudSiteId, tenantId, "VDU", "DeleteVdu", MsoLogger.ErrorCode.DataError, "Exception - DeleteVdu", ve);
            LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
            throw new VnfException (ve);
        }
        LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully roll back VF Module");
        return;
    }


    private VnfStatus vduStatusToVnfStatus (VduInstance vdu) {
    	// Determine the status based on last action & status
    	// DeploymentInfo object should be enhanced to report a better status internally.
    	VduStatus vduStatus = vdu.getStatus();
    	VduStateType status = vduStatus.getState();

    	if (status == null) {
    		return VnfStatus.UNKNOWN;
    	}
    	else if (status == VduStateType.NOTFOUND) {
			return VnfStatus.NOTFOUND;
	}
    	else if (status == VduStateType.INSTANTIATED) {
    			return VnfStatus.ACTIVE;
    	}
    	else if (status == VduStateType.FAILED) {
    		return VnfStatus.FAILED;
    	}

    	return VnfStatus.UNKNOWN;
    }

	/*
	 * Normalize an input value to an Object, based on the target parameter type.
	 * If the type is not recognized, it will just be returned unchanged (as a string).
	 */
	private Object convertInputValue (String inputValue, HeatTemplateParam templateParam)
	{
		String type = templateParam.getParamType();
		LOGGER.debug("Parameter: " + templateParam.getParamName() + " is of type " + type);

		if (type.equalsIgnoreCase("number")) {
			try {
				return Integer.valueOf(inputValue);
			}
			catch (Exception e) {
				LOGGER.debug("Unable to convert " + inputValue + " to an integer!" , e);
				return null;
			}
		} else if (type.equalsIgnoreCase("json")) {
			try {
				JsonNode jsonNode = new ObjectMapper().readTree(inputValue);
				return jsonNode;
			}
			catch (Exception e) {
				LOGGER.debug("Unable to convert " + inputValue + " to a JsonNode!", e);
				return null;
			}
		} else if (type.equalsIgnoreCase("boolean")) {
			return new Boolean(inputValue);
		}

		// Nothing else matched.  Return the original string
		return inputValue;
	}

    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", e);
            	}
            } 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", e);
            	}
            } 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", e);
            	}
            } 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(), e);
            	}
            }
        }
        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, e);
                        //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, 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();
                        stringMap.put(key, str);
                    } catch (Exception e) {
						LOGGER.debug("DANGER WILL ROBINSON: unable to convert value "+ key + " (" + e.getMessage() + ")", e);
                    }
                }
            }
        }

        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 collection of artifacts that
     * are used to deploy the required cloud resources (VMs, networks, etc.).
     *
     * Depending on the module templates, 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 VF Module instance ID in the cloud
     * @param outputs Holder for Map of VNF outputs from Deployment (assigned IPs, etc)
     * @param rollback Holder for returning VnfRollback object
     */
    @Override
    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,
            Boolean enableBridge,
            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", "VDU", "", 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<>();
        	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

        VfModule vfModule = null;
    	VnfResource vnfResource = null;
    	VfModuleCustomization vfModuleCust = null;

        try {
        	vfModuleCust = vfModuleCustomRepo.findByModelCustomizationUUID(modelCustomizationUuid);

            if (vfModuleCust == 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 " + vfModuleCust.toString());
            }

            // Get the vfModule and vnfResource records
        	vfModule = vfModuleCust.getVfModule();
        	vnfResource = vfModuleCust.getVfModule().getVnfResources();
        }
        catch (Exception e) {

        	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> cloudSiteOp = cloudConfig.getCloudSite (cloudSiteId);
        if (!cloudSiteOp.isPresent()) {
            throw new VnfException (new MsoCloudSiteNotFound (cloudSiteId));
        }
        CloudSite cloudSite = cloudSiteOp.get();
		MavenLikeVersioning aicV = new MavenLikeVersioning();
		aicV.setVersion(cloudSite.getCloudVersion());
		Boolean usingMulticloud = getUsingMulticloud(cloudSite);

		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: " + cloudSiteId + " with AIC_Version:" + cloudSite.getCloudVersion();
			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


        VduInstance vduInstance = null;
        CloudInfo cloudInfo = new CloudInfo (cloudSiteId, tenantId, null);

        // Use the VduPlugin.
        VduPlugin vduPlugin = getVduPlugin(cloudSiteId);

        // First, look up to see if the VF already exists, unless using multicloud adapter

        long subStartTime1 = System.currentTimeMillis ();
        if (!usingMulticloud) {
            try {
                vduInstance = vduPlugin.queryVdu (cloudInfo, vfModuleName);
                LOGGER.recordMetricEvent (subStartTime1, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from VduPlugin", "VDU", "QueryVDU", vfModuleName);
            }
            catch (VduException me) {
                // Failed to query the VDU due to a plugin exception.
                String error = "Create VF Module: Query " + vfModuleName + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
                LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "Exception - queryVdu", me);
                LOGGER.recordMetricEvent (subStartTime1, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVdu", 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 (vduInstance != null && !(vduInstance.getStatus().getState() == VduStateType.NOTFOUND)) {
        	VduStateType status = vduInstance.getStatus().getState();
			LOGGER.debug ("Found Existing VDU, status=" + status);

        	if (status == VduStateType.INSTANTIATED) {
        		if (failIfExists != null && failIfExists) {
            		// fail - it exists
        			String error = "Create VF: Deployment " + vfModuleName + " already exists in " + cloudSiteId + "/" + tenantId;
        			LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + vfModuleName + " already exists");
                    LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
        			throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, vduInstance.getVduInstanceId());
        		} else {
        			// Found existing deployment and client has not requested "failIfExists".
        			// Populate the outputs from the existing deployment.

        			vnfId.value = vduInstance.getVduInstanceId();
        			outputs.value = copyStringOutputs (vduInstance.getOutputs ());
                    LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module (found existing)");
                    return;
        		}
        	}
        	// Check through various detailed error cases
        	else if (status == VduStateType.INSTANTIATING || status == VduStateType.DELETING || status == VduStateType.UPDATING) {
        		// 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, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + vfModuleName + " already exists");
                LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
                throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, vduInstance.getVduInstanceId());
        	}
        	else if (status == VduStateType.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, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + vfModuleName + " already exists and is in FAILED state");
                LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error);
                throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, vduInstance.getVduInstanceId());
        	}
        	else if (status == VduStateType.UNKNOWN) {
        		// 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, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + 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, vduInstance.getVduInstanceId());
        	}
        	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, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + 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, vduInstance.getVduInstanceId());
        	}
        }


        // 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 (!usingMulticloud && volumeGroupId != null) {
            long subStartTime2 = System.currentTimeMillis ();
            VduInstance volumeVdu = null;
            try {
                volumeVdu = vduPlugin.queryVdu (cloudInfo, volumeGroupId);
                LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Success response from VduPlugin", "VDU", "QueryVdu", volumeGroupId);
            }
            catch (VduException me) {
                // Failed to query the Volume Group VDU due to a plugin exception.
                String error = "Create VF Module: Query Volume Group " + volumeGroupId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
                LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, volumeGroupId, cloudSiteId, tenantId, "VDU", "queryVdu(volume)", MsoLogger.ErrorCode.DataError, "Exception - queryVdu(volume)", me);
                LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVdu(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 (volumeVdu == null || volumeVdu.getStatus().getState() == VduStateType.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, "VDU", "queryVdu(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 = volumeVdu.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 (vfModule.getIsBase()) {
            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");
            }

            // Need to verify if multicloud needs to have the vaseVfModuleId passed to it.  Ignoring this for now.
            if (!usingMulticloud && baseVfModuleId != null) {
	            long subStartTime2 = System.currentTimeMillis ();
	            VduInstance baseVdu = null;
	            try {
	                baseVdu = vduPlugin.queryVdu (cloudInfo, baseVfModuleId);
	                LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Success response from VduPlugin", "VDU", "QueryVdu(Base)", baseVfModuleId);
	            }
	            catch (MsoException me) {
	                // Failed to query the Base VF Module due to a Vdu Plugin exception.
	                String error = "Create VF Module: Query Base " + baseVfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + me ;
	                LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, baseVfModuleId, cloudSiteId, tenantId, "VDU", "queryVdu(Base)", MsoLogger.ErrorCode.DataError, "Exception - queryVdu(Base)", me);
	                LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVdu(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 (baseVdu == null || baseVdu.getStatus().getState() == VduStateType.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, "VDU", "queryVdu(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 = baseVdu.getOutputs();
	        		this.sendMapToDebug(baseModuleOutputs, "baseModuleOutputs");
	        	}
            }
        }


        // NOTE:  For this section, heatTemplate is used for all template artifacts.
        // In final implementation (post-POC), the template object would either be generic or there would
        // be a separate DB Table/Object for different sub-orchestrators.

        // NOTE: The template is fixed for the VF Module.  The environment is part of the customization.

        HeatTemplate heatTemplate = null;
        HeatEnvironment heatEnvironment = null;
        if (isVolumeRequest) {
			heatTemplate = vfModule.getVolumeHeatTemplate();
			heatEnvironment = vfModuleCust.getVolumeHeatEnv();
		} else {
			heatTemplate = vfModule.getModuleHeatTemplate();
			heatEnvironment = vfModuleCust.getHeatEnvironment();
		}

		if (heatTemplate == null) {
			String error = "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType + ", reqType=" + requestType;
			LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Template ID", vfModuleType, "VNF", "", MsoLogger.ErrorCode.DataError, error);
            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 {
			LOGGER.debug ("Got HEAT Template from DB: " + heatTemplate.getHeatTemplate());
		}

        if (heatEnvironment == null) {
           String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType;
                LOGGER.error (MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Environment ID", "OpenStack", "", MsoLogger.ErrorCode.DataError, error);
                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);
        } else {
            LOGGER.debug ("Got Heat Environment from DB: " + heatEnvironment.getEnvironment());
        }


        // Create the combined set of parameters from the incoming request, base-module outputs,
        // volume-module outputs.  Also, convert all variables to their native object types.

        HashMap<String, Object> goldenInputs = new HashMap<String,Object>();
        List<String> extraInputs = new ArrayList<String>();

		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 = 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()) {
				// Add multicloud inputs
				for (String key : MsoMulticloudUtils.MULTICLOUD_INPUTS) {
					if (extraInputs.contains(key)) {
						goldenInputs.put(key, inputs.get(key));
						extraInputs.remove(key);
						if (extraInputs.isEmpty()) {
							break;
						}
					}
				}
				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));
					}
				}
			}

			// TODO:  The model should support a mechanism to pre-assign default parameter values
			// per "customization" (i.e. usage) of a given module.  In HEAT, this is specified by
			// an Environment file.  There is not a general mechanism in the model to handle this.
			// For the general case, any such parameter/values can be added dynamically to the
			// inputs (only if not already specified).

            // Check that required parameters have been supplied from any of the sources
            String missingParams = null;
            boolean checkRequiredParameters = true;
            try {
                String propertyString = this.environment.getProperty(MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS);
                if ("false".equalsIgnoreCase (propertyString) || "n".equalsIgnoreCase (propertyString)) {
                    checkRequiredParameters = false;
                    LOGGER.debug ("CheckRequiredParameters is FALSE. Will still check but then skip blocking..."
                                  + MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS);
                }
            } catch (Exception e) {
                // No problem - default is true
                LOGGER.debug ("An exception occured trying to get property " + MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS, e);
            }

            // Do the actual parameter checking.
            // Include looking at the ENV file as a valid definition of a parameter value.
            // TODO:  This handling of ENV applies only to Heat.  A general mechanism to
            // support pre-set parameter/values does not yet exist in the model.
            //
			StringBuilder sb = new StringBuilder(heatEnvironment.getEnvironment());
			MsoHeatEnvironmentEntry mhee = new MsoHeatEnvironmentEntry (sb);
            for (HeatTemplateParam parm : heatTemplate.getParameters ()) {
                if (parm.isRequired () && (!goldenInputs.containsKey (parm.getParamName ()))) {
                    if (mhee != null && mhee.containsParameter(parm.getParamName())) {
                        LOGGER.debug ("Required parameter " + parm.getParamName ()
                                      + " appears to be in environment - do not count as missing");
                    } else {
	                    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, "VDU", "", 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


		// Here we go...  ready to deploy the VF Module.
        long instantiateVduStartTime = System.currentTimeMillis ();
        if (backout == null) backout = true;

		try {
			// Construct the VDU Model structure to pass to the targeted VduPlugin
			VduModelInfo vduModel = null;
			if (! isVolumeRequest) {
				vduModel = vduMapper.mapVfModuleCustomizationToVdu(vfModuleCust);
			} else {
				vduModel = vduMapper.mapVfModuleCustVolumeToVdu(vfModuleCust);
			}

			// Invoke the VduPlugin to instantiate the VF Module
			vduInstance = vduPlugin.instantiateVdu(cloudInfo, vfModuleName, goldenInputs, vduModel, backout);

            LOGGER.recordMetricEvent (instantiateVduStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from VduPlugin", "VDU", "instantiateVdu", vfModuleName);
		}
		catch (VduException me) {
            // Failed to instantiate the VDU.
            me.addContext ("CreateVFModule");
            String error = "Create VF Module " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + me;
            LOGGER.recordMetricEvent (instantiateVduStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "instantiateVdu", vfModuleName);
            LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "VDU", "", MsoLogger.ErrorCode.DataError, "MsoException - instantiateVdu", me);
            LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
            // Convert to a generic VnfException
            throw new VnfException (me);
        }
	    catch (NullPointerException npe) {
	        String error = "Create VFModule " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + npe;
	        LOGGER.recordMetricEvent (instantiateVduStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, error, "VDU", "instantiateVdu", vfModuleName);
	        LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "VDU", "", MsoLogger.ErrorCode.DataError, "NullPointerException - instantiateVdu", npe);
	        LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, error);
	        LOGGER.debug("NULL POINTER EXCEPTION at vduPlugin.instantiateVdu", npe);
	        throw new VnfException ("NullPointerException during instantiateVdu");
	    }
		catch (Exception e) {
	        String error = "Create VFModule " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + e;
	        LOGGER.recordMetricEvent (instantiateVduStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, error, "VDU", "instantiateVdu", vfModuleName);
	        LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, error);
	        LOGGER.debug("Unhandled exception at vduPlugin.instantiateVdu", e);
	    	throw new VnfException("Exception during instantiateVdu: " + e.getMessage());
	    }


        // Reach this point if create is successful.
        // Populate remaining rollback info and response parameters.
        vfRollback.setVnfCreated (true);
        vfRollback.setVnfId (vduInstance.getVduInstanceId());
        vnfId.value = vduInstance.getVduInstanceId();
        outputs.value = copyStringOutputs (vduInstance.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 vfModuleId,
                           MsoRequest msoRequest,
                           Holder <Map <String, String>> outputs) throws VnfException
    {
        MsoLogger.setLogContext (msoRequest);
    	MsoLogger.setServiceName ("DeleteVfModule");

        LOGGER.debug ("Deleting VF Module " + vfModuleId + " in " + cloudSiteId + "/" + tenantId);
        // Will capture execution time for metrics
        long startTime = System.currentTimeMillis ();

        // Capture the output parameters on a delete, so need to query first
    	VduInstance vduInstance = null;
    	CloudInfo cloudInfo = new CloudInfo(cloudSiteId, tenantId, null);

        // Use the VduPlugin.
        VduPlugin vduPlugin = getVduPlugin(cloudSiteId);

    	try {
    		vduInstance = vduPlugin.queryVdu (cloudInfo, vfModuleId);
            LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received VDU Query response", "VDU", "QueryVDU", vfModuleId);
    	}
    	catch (VduException e) {
            // Failed to query the VDU due to a plugin exception.
            // Convert to a generic VnfException
            e.addContext ("QueryVFModule");
            String error = "Query VfModule (VDU): " + vfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + e;
            LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVNF", vfModuleId);
            LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleId, cloudSiteId, tenantId, "VDU", "QueryVFModule", MsoLogger.ErrorCode.DataError, "Exception - queryVDU", e);
            LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
            throw new VnfException (e);
    	}

        // call method which handles the conversion from Map<String,Object> to Map<String,String> for our expected Object types
        outputs.value = convertMapStringObjectToStringString(vduInstance.getOutputs());

        // Use the VduPlugin to delete the VDU.
        // The possible outcomes of deleteVdu are
        // - a vnfInstance object with status of DELETED (success)
        // - a vnfInstance object with status of NOTFOUND (VDU did not exist, treat as success)
        // - a vnfInstance object with status of FAILED (error)
        // Also, VduException could be thrown.
        long subStartTime = System.currentTimeMillis ();
        try {
        	// TODO:  Get an appropriate timeout value - require access to the model
            vduPlugin.deleteVdu(cloudInfo, vfModuleId, 5);
            LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from deleteVdu", "VDU", "DeleteVdu", vfModuleId);
        } catch (VduException me) {
            me.addContext ("DeleteVfModule");
            // Convert to a generic VnfException
            String error = "Delete VF: " + vfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + me;
            LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "DeleteVdu", "DeleteVdu", vfModuleId);
            LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vfModuleId, cloudSiteId, tenantId, "VDU", "DeleteVdu", MsoLogger.ErrorCode.DataError, "Exception - DeleteVdu: " + 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;
    }

    // Update VF Module not yet implemented for generic VDU plug-in model.
    @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 VduPlugin-orchestrated VF Modules.
        	LOGGER.debug ("Update VF Module command attempted but not supported");
        	throw new VnfException ("UpdateVfModule:  Unsupported command", MsoExceptionCategory.USERDATA);
        }

    /*
     * Dynamic selection of a VduPlugin version.  For initial tests, base on the "orchestrator"
     * defined for the target cloud.  Should really be looking at the VNF Model (ochestration_mode)
     * but we don't currently have access to that in Query and Delete cases.
     */
    private VduPlugin getVduPlugin (String cloudSiteId) {
    	Optional<CloudSite> cloudSiteOp = cloudConfig.getCloudSite(cloudSiteId);
    	if (cloudSiteOp.isPresent()) {
    		CloudSite cloudSite = cloudSiteOp.get();
    		String orchestrator = cloudSite.getOrchestrator();

    		if (orchestrator.equalsIgnoreCase("CLOUDIFY")) {
    			return cloudifyUtils;
    		}
    		else if (orchestrator.equalsIgnoreCase("HEAT")) {
    			return heatUtils;
    		}
            if (orchestrator.equalsIgnoreCase("MULTICLOUD")) {
                LOGGER.debug ("Got MulticloudUtils for vduPlugin");
                return multicloudUtils; }
    	}
        // Default - return HEAT plugin, though will fail later
    	return heatUtils;
    }

    private Boolean getUsingMulticloud (CloudSite cloudSite) {
        if (cloudSite.getOrchestrator().equalsIgnoreCase("MULTICLOUD")) {
            return true;
        } else {
            return false;
        }
    }
}