aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java
blob: 0bcb0f1c86019ae3d40f16c0c85060f7786d2ac4 (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
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
 * ================================================================================
 * Modifications Copyright (c) 2019 Samsung
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      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.onap.so.apihandlerinfra;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
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.core.MediaType;
import javax.ws.rs.core.Response;
import org.onap.so.logger.LoggingAnchor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandler.common.RequestClient;
import org.onap.so.apihandler.common.RequestClientFactory;
import org.onap.so.apihandler.common.RequestClientParameter;
import org.onap.so.apihandler.common.ResponseBuilder;
import org.onap.so.apihandler.common.ResponseHandler;
import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.CompareModelsRequest;
import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest;
import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest;
import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceScaleRequest;
import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
import org.onap.so.constants.Status;
import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.ServiceRecipe;
import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.db.request.beans.OperationStatus;
import org.onap.so.db.request.client.RequestsDbClient;
import org.onap.so.logger.ErrorCode;
import org.onap.so.logger.MessageEnum;
import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.ModelType;
import org.onap.so.serviceinstancebeans.RequestDetails;
import org.onap.so.serviceinstancebeans.RequestInfo;
import org.onap.so.serviceinstancebeans.RequestParameters;
import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
import org.onap.so.serviceinstancebeans.SubscriberInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;

@Component
@Path("/onap/so/infra/e2eServiceInstances")
@OpenAPIDefinition(info = @Info(title = "/onap/so/infra/e2eServiceInstances",
        description = "API Requests for E2E Service Instances"))

public class E2EServiceInstances {

    private HashMap<String, String> instanceIdMap = new HashMap<>();
    private static final Logger logger = LoggerFactory.getLogger(E2EServiceInstances.class);

    private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";

    private static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: ";

    private static final String SERVICE_ID = "serviceId";

    @Autowired
    private MsoRequest msoRequest;

    @Autowired
    private RequestClientFactory requestClientFactory;

    @Autowired
    private RequestsDbClient requestsDbClient;

    @Autowired
    private CatalogDbClient catalogDbClient;

    @Autowired
    private ResponseBuilder builder;

    /**
     * POST Requests for E2E Service create Instance on a version provided
     * 
     * @throws ApiException
     */

    @POST
    @Path("/{version:[vV][3-5]}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Operation(description = "Create an E2E Service Instance on a version provided", responses = @ApiResponse(
            content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
    public Response createE2EServiceInstance(String request, @PathParam("version") String version) throws ApiException {

        return processE2EserviceInstances(request, Action.createInstance, null, version);
    }

    /**
     * PUT Requests for E2E Service update Instance on a version provided
     * 
     * @throws ApiException
     */

    @PUT
    @Path("/{version:[vV][3-5]}/{serviceId}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Operation(description = "Update an E2E Service Instance on a version provided and serviceId",
            responses = @ApiResponse(
                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
    public Response updateE2EServiceInstance(String request, @PathParam("version") String version,
            @PathParam("serviceId") String serviceId) throws ApiException {

        instanceIdMap.put(SERVICE_ID, serviceId);

        return updateE2EserviceInstances(request, Action.updateInstance, version);
    }

    /**
     * DELETE Requests for E2E Service delete Instance on a specified version and serviceId
     * 
     * @throws ApiException
     */

    @DELETE
    @Path("/{version:[vV][3-5]}/{serviceId}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Operation(description = "Delete E2E Service Instance on a specified version and serviceId",
            responses = @ApiResponse(
                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
    public Response deleteE2EServiceInstance(String request, @PathParam("version") String version,
            @PathParam(SERVICE_ID) String serviceId) throws ApiException {

        instanceIdMap.put(SERVICE_ID, serviceId);

        return deleteE2EserviceInstances(request, Action.deleteInstance, instanceIdMap, version);
    }

    @GET
    @Path("/{version:[vV][3-5]}/{serviceId}/operations/{operationId}")
    @Operation(description = "Find e2eServiceInstances Requests for a given serviceId and operationId",
            responses = @ApiResponse(
                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
    @Produces(MediaType.APPLICATION_JSON)
    public Response getE2EServiceInstances(@PathParam(SERVICE_ID) String serviceId,
            @PathParam("version") String version, @PathParam("operationId") String operationId) {
        return getE2EServiceInstance(serviceId, operationId, version);
    }

    /**
     * Scale Requests for E2E Service scale Instance on a specified version
     * 
     * @throws ApiException
     */

    @POST
    @Path("/{version:[vV][3-5]}/{serviceId}/scale")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Operation(description = "Scale E2E Service Instance on a specified version", responses = @ApiResponse(
            content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
    public Response scaleE2EServiceInstance(String request, @PathParam("version") String version,
            @PathParam(SERVICE_ID) String serviceId) throws ApiException {

        logger.debug("------------------scale begin------------------");
        instanceIdMap.put(SERVICE_ID, serviceId);
        return scaleE2EserviceInstances(request, Action.scaleInstance, version);
    }

    /**
     * GET Requests for Comparing model of service instance with target version
     * 
     * @throws ApiException
     */

    @POST
    @Path("/{version:[vV][3-5]}/{serviceId}/modeldifferences")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Operation(
            description = "Find added and deleted resources of target model for the e2eserviceInstance on a given serviceId ",
            responses = @ApiResponse(
                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
    public Response compareModelwithTargetVersion(String request, @PathParam("serviceId") String serviceId,
            @PathParam("version") String version) throws ApiException {

        instanceIdMap.put(SERVICE_ID, serviceId);

        return compareModelwithTargetVersion(request, Action.compareModel, instanceIdMap, version);
    }

    private Response compareModelwithTargetVersion(String requestJSON, Action action,
            HashMap<String, String> instanceIdMap, String version) throws ApiException {

        String requestId = UUID.randomUUID().toString();

        CompareModelsRequest e2eCompareModelReq;

        ObjectMapper mapper = new ObjectMapper();
        try {
            e2eCompareModelReq = mapper.readValue(requestJSON, CompareModelsRequest.class);

        } catch (Exception e) {

            logger.debug("Mapping of request to JSON object failed : ", e);
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
                    MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(),
                    ErrorNumbers.SVC_BAD_PARAMETER, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity().toString());

            return response;
        }

        return runCompareModelBPMWorkflow(e2eCompareModelReq, requestJSON, requestId, action, version);

    }

    private Response runCompareModelBPMWorkflow(CompareModelsRequest e2eCompareModelReq, String requestJSON,
            String requestId, Action action, String version) throws ApiException {

        // Define RecipeLookupResult info here instead of query DB for efficiency
        String workflowUrl = "/mso/async/services/CompareModelofE2EServiceInstance";
        int recipeTimeout = 180;

        RequestClient requestClient;
        HttpResponse response;

        try {
            requestClient = requestClientFactory.getRequestClient(workflowUrl);

            JSONObject jjo = new JSONObject(requestJSON);
            String bpmnRequest = jjo.toString();

            // Capture audit event
            logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
            String serviceId = instanceIdMap.get(SERVICE_ID);
            String serviceType = e2eCompareModelReq.getServiceType();
            RequestClientParameter postParam = new RequestClientParameter.Builder().setRequestId(requestId)
                    .setBaseVfModule(false).setRecipeTimeout(recipeTimeout).setRequestAction(action.name())
                    .setServiceInstanceId(serviceId).setServiceType(serviceType).setRequestDetails(bpmnRequest)
                    .setALaCarte(false).build();
            response = requestClient.post(postParam);
        } catch (Exception e) {
            Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
                    MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.error("", MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
                    ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine", e);
            logger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString());
            return resp;
        }

        if (response == null) {
            Response resp =
                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
                            "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.BusinessProcessError.getValue(), "Null response from BPEL");
            logger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString());
            return resp;
        }

        ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
        int bpelStatus = respHandler.getStatus();

        return beplStatusUpdate(requestClient, respHandler, bpelStatus, version);
    }

    private Response getE2EServiceInstance(String serviceId, String operationId, String version) {

        GetE2EServiceInstanceResponse e2eServiceResponse = new GetE2EServiceInstanceResponse();

        String apiVersion = version.substring(1);

        OperationStatus operationStatus;

        try {
            operationStatus = requestsDbClient.getOneByServiceIdAndOperationId(serviceId, operationId);
        } catch (Exception e) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
                    ErrorCode.AvailabilityError.getValue(),
                    "Exception while communciate with Request DB - Infra Request Lookup", e);
            Response response =
                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
                            e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;

        }

        if (operationStatus == null) {
            Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NO_CONTENT,
                    MsoException.ServiceException, "E2E serviceId " + serviceId + " is not found in DB",
                    ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.BusinessProcessError.getValue(),
                    "Null response from RequestDB when searching by serviceId");
            logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
            return resp;

        }

        e2eServiceResponse.setOperation(operationStatus);

        return builder.buildResponse(HttpStatus.SC_OK, null, e2eServiceResponse, apiVersion);
    }

    private Response deleteE2EserviceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap,
            String version) throws ApiException {
        // TODO should be a new one or the same service instance Id
        E2EServiceInstanceDeleteRequest e2eDelReq;

        ObjectMapper mapper = new ObjectMapper();
        try {
            e2eDelReq = mapper.readValue(requestJSON, E2EServiceInstanceDeleteRequest.class);

        } catch (Exception e) {

            logger.debug("Mapping of request to JSON object failed : ", e);
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
                    MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(),
                    ErrorNumbers.SVC_BAD_PARAMETER, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        String requestId = UUID.randomUUID().toString();
        RecipeLookupResult recipeLookupResult;
        try {
            // TODO Get the service template model version uuid from AAI.
            recipeLookupResult = getServiceInstanceOrchestrationURI(null, action);
        } catch (Exception e) {
            logger.error(MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
                    ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e);

            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                    MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);

            msoRequest.createErrorRequestRecord(Status.FAILED, requestId,
                    "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }
        if (recipeLookupResult == null) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB");
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                    MsoException.ServiceException, "Recipe does not exist in catalog DB",
                    ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);

            msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Recipe does not exist in catalog DB", action,
                    ModelType.service.name(), requestJSON);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        RequestClient requestClient;
        HttpResponse response;

        try {
            requestClient = requestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI());

            JSONObject jjo = new JSONObject(requestJSON);
            jjo.put("operationId", requestId);

            String bpmnRequest = jjo.toString();

            // Capture audit event
            logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
            String serviceId = instanceIdMap.get(SERVICE_ID);
            String serviceInstanceType = e2eDelReq.getServiceType();
            RequestClientParameter clientParam = new RequestClientParameter.Builder().setRequestId(requestId)
                    .setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout())
                    .setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType)
                    .setRequestDetails(bpmnRequest).setApiVersion(version).setALaCarte(false)
                    .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
            response = requestClient.post(clientParam);

        } catch (Exception e) {
            Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
                    MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(),
                    "Exception while communicate with BPMN engine");
            logger.debug("End of the transaction, the final response is: " + resp.getEntity());
            return resp;
        }

        if (response == null) {
            Response resp =
                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
                            "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.BusinessProcessError.getValue(), "Null response from BPEL");
            logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
            return resp;
        }

        ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
        int bpelStatus = respHandler.getStatus();

        return beplStatusUpdate(requestClient, respHandler, bpelStatus, version);
    }

    private Response updateE2EserviceInstances(String requestJSON, Action action, String version) throws ApiException {

        String requestId = UUID.randomUUID().toString();
        E2EServiceInstanceRequest e2eSir;
        String serviceId = instanceIdMap.get(SERVICE_ID);

        ObjectMapper mapper = new ObjectMapper();
        try {
            e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);

        } catch (Exception e) {

            logger.debug("Mapping of request to JSON object failed : ", e);
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
                    MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(),
                    ErrorNumbers.SVC_BAD_PARAMETER, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        ServiceInstancesRequest sir = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
        sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
        try {
            parseRequest(sir, instanceIdMap, action, version, requestJSON, false, requestId);
        } catch (Exception e) {
            logger.debug("Validation failed: ", e);
            Response response =
                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException,
                            "Error parsing request.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
            if (requestId != null) {
                logger.debug("Logging failed message to the database");
            }
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        RecipeLookupResult recipeLookupResult;
        try {
            recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action);
        } catch (Exception e) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
                    ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e);
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                    MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);

            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());

            return response;
        }

        if (recipeLookupResult == null) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB");
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                    MsoException.ServiceException, "Recipe does not exist in catalog DB",
                    ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());

            return response;
        }

        String serviceInstanceType = e2eSir.getService().getServiceType();

        RequestClient requestClient;
        HttpResponse response;

        String sirRequestJson = convertToString(sir);

        try {
            requestClient = requestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI());

            // Capture audit event
            logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
            RequestClientParameter postParam = new RequestClientParameter.Builder().setRequestId(requestId)
                    .setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout())
                    .setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType)
                    .setRequestDetails(sirRequestJson).setApiVersion(version).setALaCarte(false)
                    .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
            response = requestClient.post(postParam);
        } catch (Exception e) {
            logger.debug("Exception while communicate with BPMN engine", e);
            Response getBPMNResp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
                    MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);

            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(),
                    "Exception while communicate with BPMN engine");
            logger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity());

            return getBPMNResp;
        }

        if (response == null) {
            Response getBPMNResp =
                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
                            "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.BusinessProcessError.getValue(), "Null response from BPEL");
            logger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity());
            return getBPMNResp;
        }

        ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
        int bpelStatus = respHandler.getStatus();

        return beplStatusUpdate(requestClient, respHandler, bpelStatus, version);
    }

    private Response processE2EserviceInstances(String requestJSON, Action action,
            HashMap<String, String> instanceIdMap, String version) throws ApiException {

        String requestId = UUID.randomUUID().toString();
        E2EServiceInstanceRequest e2eSir;

        MsoRequest msoRequest = new MsoRequest();
        ObjectMapper mapper = new ObjectMapper();
        try {
            e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);

        } catch (Exception e) {

            logger.debug("Mapping of request to JSON object failed : ", e);
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
                    MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(),
                    ErrorNumbers.SVC_BAD_PARAMETER, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        ServiceInstancesRequest sir = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
        sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
        try {
            parseRequest(sir, instanceIdMap, action, version, requestJSON, false, requestId);
        } catch (Exception e) {
            logger.debug("Validation failed: ", e);
            Response response =
                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException,
                            "Error parsing request.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
            if (requestId != null) {
                logger.debug("Logging failed message to the database");
            }
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        RecipeLookupResult recipeLookupResult;
        try {
            recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action);
        } catch (Exception e) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
                    ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e);
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                    MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        if (recipeLookupResult == null) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB");
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                    MsoException.ServiceException, "Recipe does not exist in catalog DB",
                    ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        String serviceInstanceType = e2eSir.getService().getServiceType();

        String serviceId = e2eSir.getService().getServiceId();
        RequestClient requestClient;
        HttpResponse response;

        String sirRequestJson = convertToString(sir);

        try {
            requestClient = requestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI());

            // Capture audit event
            logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
            RequestClientParameter parameter = new RequestClientParameter.Builder().setRequestId(requestId)
                    .setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout())
                    .setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType)
                    .setRequestDetails(sirRequestJson).setApiVersion(version).setALaCarte(false)
                    .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
            response = requestClient.post(parameter);
        } catch (Exception e) {
            Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
                    MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);

            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(),
                    "Exception while communicate with BPMN engine");
            logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
            return resp;
        }

        if (response == null) {
            Response resp =
                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
                            "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.BusinessProcessError.getValue(), "Null response from BPEL");
            logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
            return resp;
        }

        ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
        int bpelStatus = respHandler.getStatus();

        return beplStatusUpdate(requestClient, respHandler, bpelStatus, version);
    }

    private Response scaleE2EserviceInstances(String requestJSON, Action action, String version) throws ApiException {

        String requestId = UUID.randomUUID().toString();
        E2EServiceInstanceScaleRequest e2eScaleReq;

        ObjectMapper mapper = new ObjectMapper();
        try {
            e2eScaleReq = mapper.readValue(requestJSON, E2EServiceInstanceScaleRequest.class);

        } catch (Exception e) {

            logger.debug("Mapping of request to JSON object failed : ", e);
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
                    MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(),
                    ErrorNumbers.SVC_BAD_PARAMETER, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        RecipeLookupResult recipeLookupResult;
        try {
            // TODO Get the service template model version uuid from AAI.
            recipeLookupResult = getServiceInstanceOrchestrationURI(null, action);
        } catch (Exception e) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
                    ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e);

            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                    MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);

            msoRequest.createErrorRequestRecord(Status.FAILED, requestId,
                    "No communication to catalog DB " + e.getMessage(), action, ModelType.service.name(), requestJSON);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }
        if (recipeLookupResult == null) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB");

            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
                    MsoException.ServiceException, "Recipe does not exist in catalog DB",
                    ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
            msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "No recipe found in DB", action,
                    ModelType.service.name(), requestJSON);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }

        RequestClient requestClient;
        HttpResponse response;

        try {
            requestClient = requestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI());

            JSONObject jjo = new JSONObject(requestJSON);
            jjo.put("operationId", requestId);

            String bpmnRequest = jjo.toString();

            // Capture audit event
            logger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
            String serviceId = instanceIdMap.get(SERVICE_ID);
            String serviceInstanceType = e2eScaleReq.getService().getServiceType();
            RequestClientParameter postParam = new RequestClientParameter.Builder().setRequestId(requestId)
                    .setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout())
                    .setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType)
                    .setRequestDetails(bpmnRequest).setApiVersion(version).setALaCarte(false)
                    .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
            response = requestClient.post(postParam);
        } catch (Exception e) {
            Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
                    MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
                    ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);

            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(),
                    "Exception while communicate with BPMN engine", e);
            logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
            return resp;
        }

        if (response == null) {
            Response resp =
                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
                            "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(),
                    MSO_PROP_APIHANDLER_INFRA, ErrorCode.BusinessProcessError.getValue(), "Null response from BPEL");
            logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
            return resp;
        }

        ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
        int bpelStatus = respHandler.getStatus();

        return beplStatusUpdate(requestClient, respHandler, bpelStatus, version);
    }

    private Response beplStatusUpdate(RequestClient requestClient, ResponseHandler respHandler, int bpelStatus,
            String version) {

        String apiVersion = version.substring(1);

        // BPMN accepted the request, the request is in progress
        if (bpelStatus == HttpStatus.SC_ACCEPTED) {
            String camundaJSONResponseBody = respHandler.getResponseBody();
            logger.debug("Received from Camunda: " + camundaJSONResponseBody);
            logger.debug(END_OF_THE_TRANSACTION + camundaJSONResponseBody);
            return builder.buildResponse(HttpStatus.SC_ACCEPTED, null, camundaJSONResponseBody, apiVersion);
        } else {
            List<String> variables = new ArrayList<>();
            variables.add(bpelStatus + "");
            String camundaJSONResponseBody = respHandler.getResponseBody();
            if (camundaJSONResponseBody != null && !camundaJSONResponseBody.isEmpty()) {
                Response resp = msoRequest.buildServiceErrorResponse(bpelStatus, MsoException.ServiceException,
                        "Request Failed due to BPEL error with HTTP Status= %1 " + '\n' + camundaJSONResponseBody,
                        ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, variables, version);
                logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_RESPONSE_ERROR.toString(),
                        requestClient.getUrl(), ErrorCode.BusinessProcessError.getValue(),
                        "Response from BPEL engine is failed with HTTP Status=" + bpelStatus);
                logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
                return resp;
            } else {
                Response resp = msoRequest.buildServiceErrorResponse(bpelStatus, MsoException.ServiceException,
                        "Request Failed due to BPEL error with HTTP Status= %1",
                        ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, variables, version);
                logger.error("", MessageEnum.APIH_BPEL_RESPONSE_ERROR.toString(), requestClient.getUrl(),
                        ErrorCode.BusinessProcessError.getValue(), "Response from BPEL engine is empty");
                logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
                return resp;
            }
        }
    }

    /**
     * Getting recipes from catalogDb
     * 
     * @param serviceModelUUID the service model version uuid
     * @param action the action for the service
     * @return the service recipe result
     */
    private RecipeLookupResult getServiceInstanceOrchestrationURI(String serviceModelUUID, Action action) {

        RecipeLookupResult recipeLookupResult = getServiceURI(serviceModelUUID, action);

        if (recipeLookupResult != null) {
            logger.debug("Orchestration URI is: " + recipeLookupResult.getOrchestrationURI() + ", recipe Timeout is: "
                    + Integer.toString(recipeLookupResult.getRecipeTimeout()));
        } else {
            logger.debug("No matching recipe record found");
        }
        return recipeLookupResult;
    }

    /**
     * Getting recipes from catalogDb If Service recipe is not set, use default recipe, if set , use special recipe.
     * 
     * @param serviceModelUUID the service version uuid
     * @param action the action of the service.
     * @return the service recipe result.
     */
    private RecipeLookupResult getServiceURI(String serviceModelUUID, Action action) {

        String defaultServiceModelName = "UUI_DEFAULT";

        Service defaultServiceRecord =
                catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
        // set recipe as default generic recipe
        ServiceRecipe recipe =
                catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name());
        // check the service special recipe
        if (null != serviceModelUUID && !serviceModelUUID.isEmpty()) {
            ServiceRecipe serviceSpecialRecipe =
                    catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceModelUUID, action.name());
            if (null != serviceSpecialRecipe) {
                // set service special recipe.
                recipe = serviceSpecialRecipe;
            }
        }

        if (recipe == null) {
            return null;
        }
        return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout(), recipe.getParamXsd());

    }

    /**
     * Converting E2EServiceInstanceRequest to ServiceInstanceRequest and passing it to camunda engine.
     * 
     * @param e2eSir
     * @return
     */
    private ServiceInstancesRequest mapReqJsonToSvcInstReq(E2EServiceInstanceRequest e2eSir, String requestJSON) {

        ServiceInstancesRequest sir = new ServiceInstancesRequest();

        RequestDetails requestDetails = new RequestDetails();
        ModelInfo modelInfo = new ModelInfo();

        // ModelInvariantId
        modelInfo.setModelInvariantId(e2eSir.getService().getServiceInvariantUuid());

        // modelNameVersionId
        modelInfo.setModelNameVersionId(e2eSir.getService().getServiceUuid());

        // String modelInfoValue =
        // e2eSir.getService().getParameters().getNodeTemplateName();
        // String[] arrayOfInfo = modelInfoValue.split(":");
        // String modelName = arrayOfInfo[0];
        // String modelVersion = arrayOfInfo[1];

        // TODO: To ensure, if we dont get the values from the UUI
        String modelName = "voLTE";
        String modelVersion = "1.0";
        // modelName
        modelInfo.setModelName(modelName);

        // modelVersion
        modelInfo.setModelVersion(modelVersion);

        // modelType
        modelInfo.setModelType(ModelType.service);

        // setting modelInfo to requestDetails
        requestDetails.setModelInfo(modelInfo);

        SubscriberInfo subscriberInfo = new SubscriberInfo();

        // globalsubscriberId
        subscriberInfo.setGlobalSubscriberId(e2eSir.getService().getGlobalSubscriberId());

        // setting subscriberInfo to requestDetails
        requestDetails.setSubscriberInfo(subscriberInfo);

        RequestInfo requestInfo = new RequestInfo();

        // instanceName
        requestInfo.setInstanceName(e2eSir.getService().getName());

        // source
        requestInfo.setSource("UUI");

        // suppressRollback
        requestInfo.setSuppressRollback(true);

        // setting requestInfo to requestDetails
        requestDetails.setRequestInfo(requestInfo);

        RequestParameters requestParameters = new RequestParameters();

        // subscriptionServiceType
        requestParameters.setSubscriptionServiceType("MOG");


        List<Map<String, Object>> userParamList = new ArrayList<>();
        Map<String, Object> userParamMap = new HashMap<>();
        // complete json request updated in the camunda
        userParamMap.put("UUIRequest", requestJSON);
        userParamMap.put("ServiceInstanceName", e2eSir.getService().getName());


        userParamList.add(userParamMap);
        requestParameters.setUserParams(userParamList);

        // setting requestParameters to requestDetails
        requestDetails.setRequestParameters(requestParameters);

        sir.setRequestDetails(requestDetails);

        return sir;
    }


    private void parseRequest(ServiceInstancesRequest sir, HashMap<String, String> instanceIdMap, Action action,
            String version, String requestJSON, Boolean aLaCarte, String requestId) throws ValidateException {
        int reqVersion = Integer.parseInt(version.substring(1));
        try {
            msoRequest.parse(sir, instanceIdMap, action, version, requestJSON, reqVersion, aLaCarte);
        } catch (Exception e) {
            ErrorLoggerInfo errorLoggerInfo =
                    new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError)
                            .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
            ValidateException validateException =
                    new ValidateException.Builder("Error parsing request: " + e.getMessage(), HttpStatus.SC_BAD_REQUEST,
                            ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();

            msoRequest.createErrorRequestRecord(Status.FAILED, requestId, validateException.getMessage(), action,
                    ModelType.service.name(), requestJSON);

            throw validateException;
        }
    }

    private String convertToString(ServiceInstancesRequest sir) {
        String returnString = null;
        // converting to string
        ObjectMapper mapper = new ObjectMapper();
        try {
            returnString = mapper.writeValueAsString(sir);
        } catch (IOException e) {
            logger.debug("Exception while converting ServiceInstancesRequest object to string", e);
        }

        return returnString;
    }
}