Calls to/from VNFM fail
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / OofUtils.groovy
index 8ce6338..2f46630 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2018 Intel Corp. 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
@@ -23,7 +25,7 @@ package org.onap.so.bpmn.common.scripts
 import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
-import org.onap.so.bpmn.common.scripts.MsoUtils
+import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.domain.HomingSolution
 import org.onap.so.bpmn.core.domain.ModelInfo
 import org.onap.so.bpmn.core.domain.Resource
@@ -33,22 +35,37 @@ import org.onap.so.bpmn.core.domain.ServiceInstance
 import org.onap.so.bpmn.core.domain.Subscriber
 import org.onap.so.bpmn.core.domain.VnfResource
 import org.onap.so.bpmn.core.json.JsonUtils
-import org.onap.so.logger.MsoLogger
-
-import java.lang.reflect.Array
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.db.catalog.beans.CloudSite
+import org.onap.so.db.catalog.beans.HomingInstance
+import org.onap.so.utils.TargetEntity
+import org.springframework.http.HttpEntity
+import org.springframework.http.HttpHeaders
+import org.springframework.http.HttpMethod
+import org.springframework.http.ResponseEntity
+import org.springframework.http.client.BufferingClientHttpRequestFactory
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
+import org.springframework.web.client.RestTemplate
+import org.springframework.web.util.UriComponentsBuilder
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import javax.ws.rs.core.MediaType
+import javax.ws.rs.core.Response
+import javax.xml.ws.http.HTTPException
 
 import static org.onap.so.bpmn.common.scripts.GenericUtils.*
 
 class OofUtils {
-       private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, OofUtils.class);
+    private static final Logger logger = LoggerFactory.getLogger( OofUtils.class);
+
     ExceptionUtil exceptionUtil = new ExceptionUtil()
     JsonUtils jsonUtil = new JsonUtils()
 
     private AbstractServiceTaskProcessor utils
 
-    public MsoUtils msoUtils = new MsoUtils()
-
-    public OofUtils(AbstractServiceTaskProcessor taskProcessor) {
+    OofUtils(AbstractServiceTaskProcessor taskProcessor) {
         this.utils = taskProcessor
     }
 
@@ -75,144 +92,155 @@ class OofUtils {
                         ArrayList existingCandidates = null,
                         ArrayList excludedCandidates = null,
                         ArrayList requiredCandidates = null) {
-        def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-        utils.log("DEBUG", "Started Building OOF Request", isDebugEnabled)
-        def callbackUrl = utils.createWorkflowMessageAdapterCallbackURL(execution, "oofResponse", requestId)
-        def transactionId = requestId
-        //ServiceInstance Info
-        ServiceInstance serviceInstance = decomposition.getServiceInstance()
-        def serviceInstanceId = ""
-        def serviceName = ""
-
-        serviceInstanceId = execution.getVariable("serviceInstanceId")
-        serviceName = execution.getVariable("subscriptionServiceType")
-
-        if (serviceInstanceId == null || serviceInstanceId == "null") {
-            utils.log("DEBUG", "Unable to obtain Service Instance Id", isDebugEnabled)
-            exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - Unable to " +
-                    "obtain Service Instance Id, execution.getVariable(\"serviceInstanceId\") is null")
-        }
-        if (serviceName == null || serviceName == "null") {
-            utils.log("DEBUG", "Unable to obtain Service Name", isDebugEnabled)
-            exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - Unable to " +
-                    "obtain Service Name, execution.getVariable(\"subscriptionServiceType\") is null")
-        }
-        //Model Info
-        ModelInfo model = decomposition.getModelInfo()
-        String modelType = model.getModelType()
-        String modelInvariantId = model.getModelInvariantUuid()
-        String modelVersionId = model.getModelUuid()
-        String modelName = model.getModelName()
-        String modelVersion = model.getModelVersion()
-        //Subscriber Info
-        String subscriberId = ""
-        String subscriberName = ""
-        String commonSiteId = ""
-        if (subscriber != null){
-            subscriberId = subscriber.getGlobalId()
-            subscriberName = subscriber.getName()
-            commonSiteId = subscriber.getCommonSiteId()
-        }
-
-        //Determine RequestType
-        //TODO Figure out better way to determine this
-        String requestType = "create"
-        List<Resource> resources = decomposition.getServiceResources()
-        for(Resource r:resources){
-            HomingSolution currentSolution = (HomingSolution) r.getCurrentHomingSolution()
-            if(currentSolution != null){
-                requestType = "speed changed"
+        logger.debug( "Started Building OOF Request")
+        String callbackEndpoint = UrnPropertiesReader.getVariable("mso.oof.callbackEndpoint", execution)
+        logger.debug( "mso.oof.callbackEndpoint is: " + callbackEndpoint)
+        try {
+            def callbackUrl = utils.createHomingCallbackURL(callbackEndpoint, "oofResponse", requestId)
+            logger.debug( "callbackUrl is: " + callbackUrl)
+
+
+            def transactionId = requestId
+            logger.debug( "transactionId is: " + transactionId)
+            //ServiceInstance Info
+            ServiceInstance serviceInstance = decomposition.getServiceInstance()
+            def serviceInstanceId = ""
+            def serviceName = ""
+
+            serviceInstanceId = execution.getVariable("serviceInstanceId")
+            logger.debug( "serviceInstanceId is: " + serviceInstanceId)
+            serviceName = execution.getVariable("subscriptionServiceType")
+            logger.debug( "serviceName is: " + serviceName)
+
+            if (serviceInstanceId == null || serviceInstanceId == "null") {
+                logger.debug( "Unable to obtain Service Instance Id")
+                exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - Unable to " +
+                        "obtain Service Instance Id, execution.getVariable(\"serviceInstanceId\") is null")
+            }
+            if (serviceName == null || serviceName == "null") {
+                logger.debug( "Unable to obtain Service Name")
+                exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - Unable to " +
+                        "obtain Service Name, execution.getVariable(\"subscriptionServiceType\") is null")
+            }
+            //Model Info
+            ModelInfo model = decomposition.getModelInfo()
+            logger.debug( "ModelInfo: " + model.toString())
+            String modelType = model.getModelType()
+            String modelInvariantId = model.getModelInvariantUuid()
+            String modelVersionId = model.getModelUuid()
+            String modelName = model.getModelName()
+            String modelVersion = model.getModelVersion()
+            //Subscriber Info
+            String subscriberId = ""
+            String subscriberName = ""
+            String commonSiteId = ""
+            if (subscriber != null) {
+                subscriberId = subscriber.getGlobalId()
+                subscriberName = subscriber.getName()
+                commonSiteId = subscriber.getCommonSiteId()
             }
-        }
 
-        //Demands
-        String placementDemands = ""
-        StringBuilder sb = new StringBuilder()
-        List<AllottedResource> allottedResourceList = decomposition.getAllottedResources()
-        List<VnfResource> vnfResourceList = decomposition.getVnfResources()
+            //Determine RequestType
+            //TODO Figure out better way to determine this
+            String requestType = "create"
+            List<Resource> resources = decomposition.getServiceResources()
+            for (Resource r : resources) {
+                HomingSolution currentSolution = (HomingSolution) r.getCurrentHomingSolution()
+                if (currentSolution != null) {
+                    requestType = "speed changed"
+                }
+            }
 
-        if (allottedResourceList == null || allottedResourceList.isEmpty() ) {
-            utils.log("DEBUG", "Allotted Resources List is empty - will try to get service VNFs instead.",
-                    isDebugEnabled)
-            allottedResourceList = decomposition.getVnfResources()
-        }
+            //Demands
+            String placementDemands = ""
+            StringBuilder sb = new StringBuilder()
+            List<AllottedResource> allottedResourceList = decomposition.getAllottedResources()
+            List<VnfResource> vnfResourceList = decomposition.getVnfResources()
 
-        if (allottedResourceList == null || allottedResourceList.isEmpty()) {
-            utils.log("DEBUG", "Resources List is Empty", isDebugEnabled)
-        } else {
-            for (AllottedResource resource : allottedResourceList) {
-                utils.log("DEBUG", "Allotted Resource: " + resource.toString(),
-                        isDebugEnabled)
-                def serviceResourceId = resource.getResourceId()
-                def resourceModelInvariantId = resource.getModelInfo().getModelInvariantUuid()
-                def resourceModelVersionId = resource.getModelInfo().getModelUuid()
-                def resourceModelName = resource.getModelInfo().getModelName()
-                def resourceModelVersion = resource.getModelInfo().getModelVersion()
-                def resourceModelType = resource.getModelInfo().getModelType()
-                def tenantId = execution.getVariable("tenantId")
-                def requiredCandidatesJson = ""
-
-                requiredCandidatesJson = createCandidateJson(
-                        existingCandidates,
-                        excludedCandidates,
-                        requiredCandidates)
-
-                String demand =
-                        "      {\n" +
-                        "      \"resourceModuleName\": \"${resourceModelName}\",\n" +
-                        "      \"serviceResourceId\": \"${serviceResourceId}\",\n" +
-                        "      \"tenantId\": \"${tenantId}\",\n" +
-                        "      \"resourceModelInfo\": {\n" +
-                        "        \"modelInvariantId\": \"${resourceModelInvariantId}\",\n" +
-                        "        \"modelVersionId\": \"${resourceModelVersionId}\",\n" +
-                        "        \"modelName\": \"${resourceModelName}\",\n" +
-                        "        \"modelType\": \"${resourceModelType}\",\n" +
-                        "        \"modelVersion\": \"${resourceModelVersion}\",\n" +
-                        "        \"modelCustomizationName\": \"\"\n" +
-                        "        }" + requiredCandidatesJson + "\n" +
-                        "      },"
-
-                placementDemands = sb.append(demand)
+            if (allottedResourceList == null || allottedResourceList.isEmpty()) {
+                logger.debug( "Allotted Resources List is empty - will try to get service VNFs instead.")
+            } else {
+                for (AllottedResource resource : allottedResourceList) {
+                    logger.debug( "Allotted Resource: " + resource.toString())
+                    def serviceResourceId = resource.getResourceId()
+                    def toscaNodeType = resource.getToscaNodeType()
+                    def resourceModuleName = toscaNodeType.substring(toscaNodeType.lastIndexOf(".") + 1)
+                    def resourceModelInvariantId = resource.getModelInfo().getModelInvariantUuid()
+                    def resourceModelVersionId = resource.getModelInfo().getModelUuid()
+                    def resourceModelName = resource.getModelInfo().getModelName()
+                    def resourceModelVersion = resource.getModelInfo().getModelVersion()
+                    def resourceModelType = resource.getModelInfo().getModelType()
+                    def tenantId = execution.getVariable("tenantId")
+                    def requiredCandidatesJson = ""
+
+                    requiredCandidatesJson = createCandidateJson(
+                            existingCandidates,
+                            excludedCandidates,
+                            requiredCandidates)
+
+                    String demand =
+                            "      {\n" +
+                                    "      \"resourceModuleName\": \"${resourceModuleName}\",\n" +
+                                    "      \"serviceResourceId\": \"${serviceResourceId}\",\n" +
+                                    "      \"tenantId\": \"${tenantId}\",\n" +
+                                    "      \"resourceModelInfo\": {\n" +
+                                    "        \"modelInvariantId\": \"${resourceModelInvariantId}\",\n" +
+                                    "        \"modelVersionId\": \"${resourceModelVersionId}\",\n" +
+                                    "        \"modelName\": \"${resourceModelName}\",\n" +
+                                    "        \"modelType\": \"${resourceModelType}\",\n" +
+                                    "        \"modelVersion\": \"${resourceModelVersion}\",\n" +
+                                    "        \"modelCustomizationName\": \"\"\n" +
+                                    "        }" + requiredCandidatesJson + "\n" +
+                                    "      },"
+
+                    placementDemands = sb.append(demand)
+                }
             }
-            for (VnfResource vnfResource : vnfResourceList) {
-                utils.log("DEBUG", "VNF Resource: " + vnfResource.toString(),
-                        isDebugEnabled)
-                ModelInfo vnfResourceModelInfo = vnfResource.getModelInfo()
-                def serviceResourceId = vnfResource.getResourceId()
-                def resourceModelInvariantId = vnfResourceModelInfo.getModelInvariantUuid()
-                def resourceModelName = vnfResourceModelInfo.getModelName()
-                def resourceModelVersion = vnfResourceModelInfo.getModelVersion()
-                def resourceModelVersionId = vnfResourceModelInfo.getModelUuid()
-                def resourceModelType = vnfResourceModelInfo.getModelType()
-                def tenantId = execution.getVariable("tenantId")
-                def requiredCandidatesJson = ""
-
-
-                String placementDemand =
-                        "      {\n" +
-                        "      \"resourceModuleName\": \"${resourceModelName}\",\n" +
-                        "      \"serviceResourceId\": \"${serviceResourceId}\",\n" +
-                        "      \"tenantId\": \"${tenantId}\",\n" +
-                        "      \"resourceModelInfo\": {\n" +
-                        "        \"modelInvariantId\": \"${resourceModelInvariantId}\",\n" +
-                        "        \"modelVersionId\": \"${resourceModelVersionId}\",\n" +
-                        "        \"modelName\": \"${resourceModelName}\",\n" +
-                        "        \"modelType\": \"${resourceModelType}\",\n" +
-                        "        \"modelVersion\": \"${resourceModelVersion}\",\n" +
-                        "        \"modelCustomizationName\": \"\"\n" +
-                        "        }" + requiredCandidatesJson + "\n" +
-                        "      },"
-
-                placementDemands = sb.append(placementDemand)
+
+            if (vnfResourceList == null || vnfResourceList.isEmpty()) {
+                logger.debug( "VNF Resources List is empty")
+            } else {
+
+                for (VnfResource vnfResource : vnfResourceList) {
+                    logger.debug( "VNF Resource: " + vnfResource.toString())
+                    ModelInfo vnfResourceModelInfo = vnfResource.getModelInfo()
+                    def toscaNodeType = vnfResource.getToscaNodeType()
+                    def resourceModuleName = toscaNodeType.substring(toscaNodeType.lastIndexOf(".") + 1)
+                    def serviceResourceId = vnfResource.getResourceId()
+                    def resourceModelInvariantId = vnfResourceModelInfo.getModelInvariantUuid()
+                    def resourceModelName = vnfResourceModelInfo.getModelName()
+                    def resourceModelVersion = vnfResourceModelInfo.getModelVersion()
+                    def resourceModelVersionId = vnfResourceModelInfo.getModelUuid()
+                    def resourceModelType = vnfResourceModelInfo.getModelType()
+                    def tenantId = execution.getVariable("tenantId")
+                    def requiredCandidatesJson = ""
+
+
+                    String placementDemand =
+                            "      {\n" +
+                                    "      \"resourceModuleName\": \"${resourceModuleName}\",\n" +
+                                    "      \"serviceResourceId\": \"${serviceResourceId}\",\n" +
+                                    "      \"tenantId\": \"${tenantId}\",\n" +
+                                    "      \"resourceModelInfo\": {\n" +
+                                    "        \"modelInvariantId\": \"${resourceModelInvariantId}\",\n" +
+                                    "        \"modelVersionId\": \"${resourceModelVersionId}\",\n" +
+                                    "        \"modelName\": \"${resourceModelName}\",\n" +
+                                    "        \"modelType\": \"${resourceModelType}\",\n" +
+                                    "        \"modelVersion\": \"${resourceModelVersion}\",\n" +
+                                    "        \"modelCustomizationName\": \"\"\n" +
+                                    "        }" + requiredCandidatesJson + "\n" +
+                                    "      },"
+
+                    placementDemands = sb.append(placementDemand)
+                }
+                placementDemands = placementDemands.substring(0, placementDemands.length() - 1)
             }
-            placementDemands = placementDemands.substring(0, placementDemands.length() - 1)
-        }
 
-        /* Commenting Out Licensing as OOF doesn't support for Beijing
+            /* Commenting Out Licensing as OOF doesn't support for Beijing
         String licenseDemands = ""
         sb = new StringBuilder()
         if (vnfResourceList.isEmpty() || vnfResourceList == null) {
-            utils.log("DEBUG", "Vnf Resources List is Empty", isDebugEnabled)
+            logger.debug( "Vnf Resources List is Empty")
         } else {
             for (VnfResource vnfResource : vnfResourceList) {
                 ModelInfo vnfResourceModelInfo = vnfResource.getModelInfo()
@@ -253,50 +281,53 @@ class OofUtils {
             licenseDemands = licenseDemands.substring(0, licenseDemands.length() - 1)
         }*/
 
-        String request =
-                "{\n" +
-                "  \"requestInfo\": {\n" +
-                "    \"transactionId\": \"${transactionId}\",\n" +
-                "    \"requestId\": \"${requestId}\",\n" +
-                "    \"callbackUrl\": \"${callbackUrl}\",\n" +
-                "    \"sourceId\": \"so\",\n" +
-                "    \"requestType\": \"${requestType}\"," +
-                "    \"numSolutions\": 1,\n" +
-                "    \"optimizers\": [\"placement\"],\n" +
-                "    \"timeout\": 600\n" +
-                "    },\n" +
-                "  \"placementInfo\": {\n" +
-                "    \"requestParameters\": {\n" +
-                "      \"customerLatitude\": \"${customerLocation.customerLatitude}\",\n" +
-                "      \"customerLongitude\": \"${customerLocation.customerLongitude}\",\n" +
-                "      \"customerName\": \"${customerLocation.customerName}\"\n" +
-                "    }," +
-                "    \"subscriberInfo\": { \n" +
-                "      \"globalSubscriberId\": \"${subscriberId}\",\n" +
-                "      \"subscriberName\": \"${subscriberName}\",\n" +
-                "      \"subscriberCommonSiteId\": \"${commonSiteId}\"\n" +
-                "    },\n" +
-                "    \"placementDemands\": [\n" +
-                "      ${placementDemands}\n" +
-                "      ]\n" +
-                "    },\n" +
-                "  \"serviceInfo\": {\n" +
-                "    \"serviceInstanceId\": \"${serviceInstanceId}\",\n" +
-                "    \"serviceName\": \"${serviceName}\",\n" +
-                "    \"modelInfo\": {\n" +
-                "      \"modelType\": \"${modelType}\",\n" +
-                "      \"modelInvariantId\": \"${modelInvariantId}\",\n" +
-                "      \"modelVersionId\": \"${modelVersionId}\",\n" +
-                "      \"modelName\": \"${modelName}\",\n" +
-                "      \"modelVersion\": \"${modelVersion}\",\n" +
-                "      \"modelCustomizationName\": \"\"\n" +
-                "    }\n" +
-                "  }\n" +
-                "}"
-
-
-        utils.log("DEBUG", "Completed Building OOF Request", isDebugEnabled)
-        return request
+            String request =
+                    "{\n" +
+                            "  \"requestInfo\": {\n" +
+                            "    \"transactionId\": \"${transactionId}\",\n" +
+                            "    \"requestId\": \"${requestId}\",\n" +
+                            "    \"callbackUrl\": \"${callbackUrl}\",\n" +
+                            "    \"sourceId\": \"so\",\n" +
+                            "    \"requestType\": \"${requestType}\"," +
+                            "    \"numSolutions\": 1,\n" +
+                            "    \"optimizers\": [\"placement\"],\n" +
+                            "    \"timeout\": 600\n" +
+                            "    },\n" +
+                            "  \"placementInfo\": {\n" +
+                            "    \"requestParameters\": {\n" +
+                            "      \"customerLatitude\": \"${customerLocation.customerLatitude}\",\n" +
+                            "      \"customerLongitude\": \"${customerLocation.customerLongitude}\",\n" +
+                            "      \"customerName\": \"${customerLocation.customerName}\"\n" +
+                            "    }," +
+                            "    \"subscriberInfo\": { \n" +
+                            "      \"globalSubscriberId\": \"${subscriberId}\",\n" +
+                            "      \"subscriberName\": \"${subscriberName}\",\n" +
+                            "      \"subscriberCommonSiteId\": \"${commonSiteId}\"\n" +
+                            "    },\n" +
+                            "    \"placementDemands\": [\n" +
+                            "      ${placementDemands}\n" +
+                            "      ]\n" +
+                            "    },\n" +
+                            "  \"serviceInfo\": {\n" +
+                            "    \"serviceInstanceId\": \"${serviceInstanceId}\",\n" +
+                            "    \"serviceName\": \"${serviceName}\",\n" +
+                            "    \"modelInfo\": {\n" +
+                            "      \"modelType\": \"${modelType}\",\n" +
+                            "      \"modelInvariantId\": \"${modelInvariantId}\",\n" +
+                            "      \"modelVersionId\": \"${modelVersionId}\",\n" +
+                            "      \"modelName\": \"${modelName}\",\n" +
+                            "      \"modelVersion\": \"${modelVersion}\",\n" +
+                            "      \"modelCustomizationName\": \"\"\n" +
+                            "    }\n" +
+                            "  }\n" +
+                            "}"
+
+
+            logger.debug( "Completed Building OOF Request")
+            return request
+        } catch (Exception ex) {
+             logger.debug( "buildRequest Exception: " + ex)
+        }
     }
 
     /**
@@ -309,7 +340,6 @@ class OofUtils {
      * @param response - the async callback response from oof
      */
     Void validateCallbackResponse(DelegateExecution execution, String response) {
-        def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
         String placements = ""
         if (isBlank(response)) {
             exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "OOF Async Callback Response is Empty")
@@ -319,12 +349,12 @@ class OofUtils {
                 if (isBlank(placements) || placements.equalsIgnoreCase("[]")) {
                     String statusMessage = jsonUtil.getJsonValue(response, "statusMessage")
                     if (isBlank(statusMessage)) {
-                        utils.log("DEBUG", "Error Occurred in Homing: OOF Async Callback Response does " +
-                                "not contain placement solution.", isDebugEnabled)
+                        logger.debug( "Error Occurred in Homing: OOF Async Callback Response does " +
+                                "not contain placement solution.")
                         exceptionUtil.buildAndThrowWorkflowException(execution, 400,
                                 "OOF Async Callback Response does not contain placement solution.")
                     } else {
-                        utils.log("DEBUG", "Error Occurred in Homing: " + statusMessage, isDebugEnabled)
+                        logger.debug( "Error Occurred in Homing: " + statusMessage)
                         exceptionUtil.buildAndThrowWorkflowException(execution, 400, statusMessage)
                     }
                 } else {
@@ -344,11 +374,11 @@ class OofUtils {
                 } else {
                     errorMessage = "OOF Async Callback Response contains a Request Error. Unable to determine the Request Error Exception."
                 }
-                utils.log("DEBUG", "Error Occurred in Homing: " + errorMessage, isDebugEnabled)
+                logger.debug( "Error Occurred in Homing: " + errorMessage)
                 exceptionUtil.buildAndThrowWorkflowException(execution, 400, errorMessage)
 
             } else {
-                utils.log("DEBUG", "Error Occurred in Homing: Received an Unknown Async Callback Response from OOF.", isDebugEnabled)
+                logger.debug( "Error Occurred in Homing: Received an Unknown Async Callback Response from OOF.")
                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Received an Unknown Async Callback Response from OOF.")
             }
         }
@@ -466,4 +496,52 @@ class OofUtils {
         if (candidatesJson != "") {candidatesJson = candidatesJson.substring(0, candidatesJson.length() - 1)}
         return candidatesJson
     }
+
+    /**
+     * This method creates a cloudsite in catalog database.
+     *
+     * @param CloudSite cloudSite
+     *
+     * @return void
+     */
+    Void createCloudSiteCatalogDb(CloudSite cloudSite, DelegateExecution execution) {
+
+        String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution)
+        String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution)
+        String uri = "/cloudSite"
+
+           URL url = new URL(endpoint + uri)
+        HttpClient client = new HttpClientFactory().newJsonClient(url, TargetEntity.EXTERNAL)
+        client.addAdditionalHeader(HttpHeaders.AUTHORIZATION, auth)
+           client.addAdditionalHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
+
+        Response response = client.post(request.getBody().toString())
+
+        int responseCode = response.getStatus()
+        logger.debug("CatalogDB response code is: " + responseCode)
+        String syncResponse = response.readEntity(String.class)
+        logger.debug("CatalogDB response is: " + syncResponse)
+
+        if(responseCode != 202){
+            exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CatalogDB.")
+        }
+    }
+
+    /**
+     * This method creates a HomingInstance in catalog database.
+     *
+     * @param HomingInstance homingInstance
+     *
+     * @return void
+     */
+    Void createHomingInstance(HomingInstance homingInstance, DelegateExecution execution) {
+        oofInfraUtils.createHomingInstance(homingInstance, execution)
+    }
+     String getMsbHost(DelegateExecution execution) {
+         String msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap")
+
+         Integer msbPort = UrnPropertiesReader.getVariable("mso.msb.port", execution, "80").toInteger()
+
+         return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString()
+    }
 }