Fix UriBuilder import in OofUtils 29/88729/5
authorMarcus G K Williams <marcus.williams@intel.com>
Wed, 29 May 2019 03:46:03 +0000 (20:46 -0700)
committerMarcus G K Williams <marcus.williams@intel.com>
Wed, 29 May 2019 10:16:30 +0000 (03:16 -0700)
Import all changes from Casablanca
that were incorrectly removed during
merge from Casablanca back into
master.

Issue-ID: SO-1926
Change-Id: I8355e804586aa80e291f3c72a00bf69ce424316b
Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy
common/src/main/java/org/onap/so/utils/TargetEntity.java

index 623d5a6..6583ded 100644 (file)
@@ -32,17 +32,18 @@ import org.onap.so.bpmn.core.domain.ServiceDecomposition
 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.client.DefaultProperties
 import org.onap.so.client.HttpClient
 import org.onap.so.client.HttpClientFactory
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.db.catalog.beans.AuthenticationType
 import org.onap.so.db.catalog.beans.CloudIdentity
 import org.onap.so.db.catalog.beans.CloudSite
 import org.onap.so.db.catalog.beans.HomingInstance
 import org.onap.so.db.catalog.beans.ServerType
-import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.utils.TargetEntity
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
 
 import org.json.JSONArray
 import org.json.JSONObject
@@ -108,12 +109,12 @@ class OofHoming extends AbstractServiceTaskProcessor {
                 if (isBlank(subscriberInfo)) {
                     subscriber = new Subscriber("", "", "")
                 } else {
-                String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId")
-                String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName")
-                String subCommonSiteId = ""
-                if (jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")) {
-                    subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId")
-                }
+                    String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId")
+                    String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName")
+                    String subCommonSiteId = ""
+                    if (jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")) {
+                        subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId")
+                    }
                     subscriber = new Subscriber(subId, subName, subCommonSiteId)
                 }
 
@@ -163,21 +164,24 @@ class OofHoming extends AbstractServiceTaskProcessor {
                 logger.debug( "Posting to OOF Url: " + urlString)
 
 
-                               URL url = new URL(urlString);
-                HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.SNIRO)
+                URL url = new URL(urlString)
+                HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.OOF)
                 httpClient.addAdditionalHeader("Authorization", authHeader)
-                               Response httpResponse = httpClient.post(oofRequest)
+                Response httpResponse = httpClient.post(oofRequest)
 
-                               int responseCode = httpResponse.getStatus()
-                               logger.debug("OOF sync response code is: " + responseCode)
+                int responseCode = httpResponse.getStatus()
+                logger.debug("OOF sync response code is: " + responseCode)
 
+                if(responseCode != 202){
+                    exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
+                }
 
                 logger.debug( "*** Completed Homing Call OOF ***")
             }
         } catch (BpmnError b) {
             throw b
         } catch (Exception e) {
-                       logger.error(e);
+            logger.error(e);
             exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
                     "Internal Error - Occured in Homing callOof: " + e.getMessage())
         }
@@ -360,7 +364,7 @@ class OofHoming extends AbstractServiceTaskProcessor {
             throw b
         } catch (Exception e) {
             logger.debug( "ProcessHomingSolution Exception: " + e)
-                       logger.error(e);
+            logger.error(e);
             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occurred in Homing ProcessHomingSolution")
         }
     }
index 2f46630..4bfb29b 100644 (file)
@@ -25,6 +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.util.OofInfraUtils
 import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.domain.HomingSolution
 import org.onap.so.bpmn.core.domain.ModelInfo
@@ -53,6 +54,7 @@ import org.slf4j.LoggerFactory
 
 import javax.ws.rs.core.MediaType
 import javax.ws.rs.core.Response
+import javax.ws.rs.core.UriBuilder
 import javax.xml.ws.http.HTTPException
 
 import static org.onap.so.bpmn.common.scripts.GenericUtils.*
@@ -62,6 +64,7 @@ class OofUtils {
 
     ExceptionUtil exceptionUtil = new ExceptionUtil()
     JsonUtils jsonUtil = new JsonUtils()
+    OofInfraUtils oofInfraUtils = new OofInfraUtils()
 
     private AbstractServiceTaskProcessor utils
 
@@ -504,27 +507,8 @@ class OofUtils {
      *
      * @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.")
-        }
+    Void createCloudSite(CloudSite cloudSite, DelegateExecution execution) {
+        oofInfraUtils.createCloudSite(cloudSite, execution)
     }
 
     /**
@@ -537,11 +521,12 @@ class OofUtils {
     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()
+    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()
+        return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString()
     }
 }
index 5f87378..ea0b704 100644 (file)
@@ -23,7 +23,7 @@ package org.onap.so.utils;
 import java.util.EnumSet;
 
 public enum TargetEntity {
-    OPENSTACK_ADAPTER, BPMN, GRM, AAI, DMAAP, POLICY, CATALOG_DB, REQUEST_DB, VNF_ADAPTER, SDNC_ADAPTER, SNIRO, SDC, EXTERNAL, MULTICLOUD;
+    OPENSTACK_ADAPTER, BPMN, GRM, AAI, DMAAP, POLICY, CATALOG_DB, REQUEST_DB, VNF_ADAPTER, SDNC_ADAPTER, SNIRO, SDC, EXTERNAL, MULTICLOUD, OOF;
 
     private static final String PREFIX = "SO";