Fix OOF Directives processing 50/72350/3
authorMarcus G K Williams <marcus.williams@intel.com>
Fri, 9 Nov 2018 23:56:17 +0000 (15:56 -0800)
committerMarcus G K Williams <marcus.williams@intel.com>
Tue, 13 Nov 2018 02:26:57 +0000 (18:26 -0800)
- Various fixes to process OOF directives
correctly
- Add orchestrator userParam Processing to ala carte
and vCPE path to ensure multicloud adapter can be
called when homing
- Fix JsonUtils to accept json object as well as
strings
- Adds JsonUtils unit tests to ensure json object
code works correctly and didn't break previous func.
- Fix OOF Homing codes processing of OOF response to
match Casablanca response from OOF (including OOF
directives)
- Add CloudIdentity get and put to catalogDBClient,
along with junit tests - to enable creation of cloudSites
- Fix serviceResourceId check

Issue-ID: SO-1203
Change-Id: Ice9a9d1da2ce0cd4bd11029e3669b30d658fe359
Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CloudConfigTest.java
adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
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
bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/json/JsonUtils.java
bpmn/MSOCoreBPMN/src/test/java/org/onap/so/bpmn/core/json/JsonUtilsTest.java
bpmn/MSOCoreBPMN/src/test/resources/json-examples/OofExample.json [new file with mode: 0644]
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateGenericALaCarteServiceInstance.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy
mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java
mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java

index 0606848..eb2d375 100644 (file)
@@ -63,14 +63,14 @@ public class CloudConfigTest {
         headers.set("Content-Type",MediaType.APPLICATION_JSON);
 
         CloudSite cloudSite = new CloudSite();
-        cloudSite.setId("MTN6");
+        cloudSite.setId("MTN7");
         cloudSite.setClli("TESTCLLI");
         cloudSite.setRegionId("regionId");
         cloudSite.setCloudVersion("VERSION");
         cloudSite.setPlatform("PLATFORM");
 
         CloudIdentity cloudIdentity = new CloudIdentity();
-        cloudIdentity.setId("RANDOMID");
+        cloudIdentity.setId("RANDOMID-test");
         cloudIdentity.setIdentityUrl("URL");
         cloudIdentity.setMsoId("MSO_ID");
         cloudIdentity.setMsoPass("MSO_PASS");
@@ -81,7 +81,7 @@ public class CloudConfigTest {
         cloudSite.setIdentityService(cloudIdentity);
         String uri = "/cloudSite";
         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri);
-        HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers);  
+        HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers);
         ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
                 HttpMethod.POST, request, String.class);
         assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value());
@@ -96,4 +96,6 @@ public class CloudConfigTest {
 
     }
 
+
+
 }
index 5e2bd82..c85a4c2 100644 (file)
@@ -413,6 +413,7 @@ public class CatalogDbClientTest {
         Assert.assertEquals("regionId", getCloudSite.getRegionId());
         Assert.assertEquals("RANDOMID", getCloudSite.getIdentityServiceId());
     }
+
    @Test
     public void testGetServiceByModelName() {
         Service service = client.getServiceByModelName("MSOTADevInfra_Test_Service");
index 806a144..c50ef35 100644 (file)
@@ -30,8 +30,10 @@ 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.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.ServerType
 import org.onap.so.rest.APIResponse
 import org.onap.so.rest.RESTClient
 import org.onap.so.rest.RESTConfig
@@ -211,17 +213,12 @@ class OofHoming extends AbstractServiceTaskProcessor {
                 for (int j = 0; j < arrSol.length(); j++) {
                     JSONObject placement = arrSol.getJSONObject(j)
                     utils.log("DEBUG", "****** Placement Solution is: " + placement + " *****", "true")
-                    String jsonServiceResourceId = placement.getString("serviceResourceId")
-                    String jsonResourceModuleName = placement.getString("resourceModuleName")
+                    String jsonServiceResourceId = jsonUtil.getJsonValue( placement.toString(), "serviceResourceId")
+                    utils.log("DEBUG", "****** homing serviceResourceId is: " + jsonServiceResourceId + " *****", "true")
                     for (Resource resource : resourceList) {
                         String serviceResourceId = resource.getResourceId()
-                        String resourceModuleName = ""
-                        if (resource.getResourceType() == ResourceType.ALLOTTED_RESOURCE ||
-                            resource.getResourceType() == ResourceType.VNF) {
-                            resourceModuleName = resource.getNfFunction()
-                            }
-                        if (serviceResourceId.equalsIgnoreCase(jsonServiceResourceId) ||
-                            resourceModuleName.equalsIgnoreCase(jsonResourceModuleName)) {
+                        utils.log("DEBUG", "****** decomp serviceResourceId is: " + serviceResourceId + " *****", "true")
+                        if (serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)) {
                             JSONObject solution = placement.getJSONObject("solution")
                             String solutionType = solution.getString("identifierType")
                             String inventoryType = ""
@@ -230,20 +227,26 @@ class OofHoming extends AbstractServiceTaskProcessor {
                             } else {
                                 inventoryType = "cloud"
                             }
+                            utils.log("DEBUG", "****** homing inventoryType is: " + inventoryType + " *****", "true")
                             resource.getHomingSolution().setInventoryType(InventoryType.valueOf(inventoryType))
 
                             JSONArray assignmentArr = placement.getJSONArray("assignmentInfo")
+                            utils.log("DEBUG", "****** assignmentInfo is: " + assignmentArr.toString() + " *****", "true")
+
+                            Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution,
+                                    assignmentArr.toString(), "key", "value")
                             String oofDirectives = null
-                            assignmentArr.each { element ->
-                                JSONObject jsonObject = new JSONObject(element.toString())
-                                if (jsonUtil.getJsonRawValue(jsonObject.toString(), "key") == "oof_directives") {
-                                    oofDirectives = jsonUtil.getJsonRawValue(jsonObject.toString(), "value")
+                            assignmentMap.each { key, value ->
+                                utils.log("DEBUG", "****** element: " + key + " *****", "true")
+                                if (key == "oof_directives") {
+                                    oofDirectives = value
+                                    utils.log("DEBUG", "****** homing oofDirectives: " + oofDirectives + " *****", "true")
                                 }
                             }
-                            Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution,
-                                    assignmentArr.toString(), "key", "value")
                             String cloudOwner = assignmentMap.get("cloudOwner")
+                            utils.log("DEBUG", "****** homing cloudOwner: " + cloudOwner + " *****", "true")
                             String cloudRegionId = assignmentMap.get("locationId")
+                            utils.log("DEBUG", "****** homing cloudRegionId: " + cloudRegionId + " *****", "true")
                             resource.getHomingSolution().setCloudOwner(cloudOwner)
                             resource.getHomingSolution().setCloudRegionId(cloudRegionId)
 
@@ -251,12 +254,26 @@ class OofHoming extends AbstractServiceTaskProcessor {
                             cloudSite.setId(cloudRegionId)
                             cloudSite.setRegionId(cloudRegionId)
                             String orchestrator = execution.getVariable("orchestrator")
-                            if ((orchestrator != null) || (orchestrator != "")) {
+                            if ((orchestrator != null) && (orchestrator != "")) {
                                 cloudSite.setOrchestrator(orchestrator)
+                                utils.log("DEBUG", "****** orchestrator: " + orchestrator + " *****", "true")
+                            } else {
+                                cloudSite.setOrchestrator("multicloud")
                             }
 
                             CloudIdentity cloudIdentity = new CloudIdentity()
                             cloudIdentity.setId(cloudRegionId)
+                            cloudIdentity.setIdentityServerType(ServerType."KEYSTONE")
+                            cloudIdentity.setAdminTenant("service")
+                            cloudIdentity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD)
+                            String msoMulticloudUserName = UrnPropertiesReader
+                                    .getVariable("mso.multicloud.api.password", execution,
+                                    "apih")
+                            String msoMulticloudPassword = UrnPropertiesReader
+                                    .getVariable("mso.multicloud.api.password", execution,
+                                    "abc123")
+                            cloudIdentity.setMsoId(msoMulticloudUserName)
+                            cloudIdentity.setMsoPass(msoMulticloudPassword)
                             // Get MSB Url
                             String msbHost = oofUtils.getMsbHost(execution)
                             String multicloudApiEndpoint = UrnPropertiesReader
@@ -265,16 +282,24 @@ class OofHoming extends AbstractServiceTaskProcessor {
                             cloudIdentity.setIdentityUrl(msbHost + multicloudApiEndpoint
                                     + "/" + cloudOwner + "/" +
                                     cloudRegionId + "/infra_workload")
-
+                            utils.log("DEBUG", "****** Cloud IdentityUrl: " + msbHost + multicloudApiEndpoint
+                                    + "/" + cloudOwner + "/" +
+                                    cloudRegionId + "/infra_workload"
+                                    + " *****", "true")
+                            utils.log("DEBUG", "****** CloudIdentity: " + cloudIdentity.toString()
+                                    + " *****", "true")
                             cloudSite.setIdentityService(cloudIdentity)
+                            utils.log("DEBUG", "****** CloudSite: " + cloudSite.toString()
+                                    + " *****", "true")
 
                             // Set cloudsite in catalog DB here
-                            oofUtils.createCloudSiteCatalogDb(cloudSite)
+                            // TODO Get cloudsite and compare, set if not present
+                            oofUtils.createCloudSiteCatalogDb(cloudSite, execution)
 
                             if (oofDirectives != null && oofDirectives != "") {
                                 resource.getHomingSolution().setOofDirectives(oofDirectives)
                                 execution.setVariable("oofDirectives", oofDirectives)
-                                utils.log("DEBUG", "***** OofDirectives is: " + oofDirectives +
+                                utils.log("DEBUG", "***** OofDirectives set to: " + oofDirectives +
                                         " *****", "true")
                             }
 
@@ -285,6 +310,12 @@ class OofHoming extends AbstractServiceTaskProcessor {
                                 resource.getHomingSolution().setVnf(vnf)
                                 resource.getHomingSolution().setServiceInstanceId(solution.getJSONArray("identifiers")[0].toString())
                             }
+                        } else {
+                            utils.log("DEBUG", "ProcessHomingSolution Exception: no matching serviceResourceIds returned in " +
+                                    "homing solution", isDebugEnabled)
+                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - " +
+                                    "Occurred in Homing ProcessHomingSolution: no matching serviceResourceIds returned")
+
                         }
                     }
                 }
@@ -314,8 +345,10 @@ class OofHoming extends AbstractServiceTaskProcessor {
 
             utils.log("DEBUG", "*** Completed Homing Process Homing Solution ***", isDebugEnabled)
         } catch (BpmnError b) {
+            utils.log("DEBUG", "ProcessHomingSolution Error: " + b, isDebugEnabled)
             throw b
         } catch (Exception e) {
+            utils.log("DEBUG", "ProcessHomingSolution Exception: " + e, isDebugEnabled)
                        msoLogger.error(e);
             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occurred in Homing ProcessHomingSolution")
         }
index 909683a..19d19b8 100644 (file)
@@ -33,22 +33,18 @@ 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.db.catalog.beans.CloudIdentity
 import org.onap.so.db.catalog.beans.CloudSite
+import org.onap.so.db.catalog.client.CatalogDbClient
 import org.onap.so.rest.APIResponse
 import org.onap.so.rest.RESTClient
 import org.onap.so.rest.RESTConfig
 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 javax.ws.rs.core.MediaType
-import javax.ws.rs.core.Response
-import javax.xml.ws.http.HTTPException
+import javax.ws.rs.core.UriBuilder
 
 import static org.onap.so.bpmn.common.scripts.GenericUtils.*
 
@@ -503,36 +499,26 @@ class OofUtils {
      * @return void
      */
     Void createCloudSiteCatalogDb(CloudSite cloudSite, DelegateExecution execution) {
-
+        def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
         String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution)
         String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution)
-        String uri = "/cloudSite"
-
-        HttpHeaders headers = new HttpHeaders()
-
-        headers.set(HttpHeaders.AUTHORIZATION, auth)
-        headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
-        headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+        CloudSite getCloudsite = null
 
-        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(endpoint + uri)
-        HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers)
-        RESTConfig config = new RESTConfig(endpoint + uri)
-        RESTClient client = new RESTClient(config).addAuthorizationHeader(auth).
-                addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
-        APIResponse response = client.httpPost(request.getBody().toString())
-
-        int responseCode = response.getStatusCode()
-        logDebug("CatalogDB response code is: " + responseCode, isDebugEnabled)
-        String syncResponse = response.getResponseBodyAsString()
-        logDebug("CatalogDB response is: " + syncResponse, isDebugEnabled)
-
-        if(responseCode != 202){
-            exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CatalogDB.")
+        CatalogDbClient catalogDbClient = new CatalogDbClient(endpoint, auth)
+        try {
+            getCloudsite = catalogDbClient.getCloudSite(cloudSite.getId().toString())
+        } catch (Exception e) {
+            e = null
+            utils.log("DEBUG", "Could not find cloudsite : " + cloudSite.getId(), isDebugEnabled)
+            utils.log("DEBUG", "Creating cloudSite: " + cloudSite.toString(), isDebugEnabled)
+        }
+        if (getCloudsite?.getId() != cloudSite.getId()) {
+            catalogDbClient.postCloudSite(cloudSite)
         }
     }
 
      String getMsbHost(DelegateExecution execution) {
-         msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap")
+         String msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap")
 
          Integer msbPort = UrnPropertiesReader.getVariable("mso.msb.port", execution, "80").toInteger()
 
index ee53148..35f7690 100644 (file)
@@ -927,7 +927,7 @@ public class JsonUtils {
                for (int i = 0; i < arr.length(); i++){
                        JSONObject jo = arr.getJSONObject(i);
                        String key = jo.getString(keyNode);
-                       String value = jo.getString(valueNode);
+                       String value = jo.get(valueNode).toString();
                        map.put(key, value);
                }
                msoLogger.debug("Completed Entry Array To Map Util Method");
@@ -954,7 +954,7 @@ public class JsonUtils {
                for(int i = 0; i < arr.length(); i++){
                        JSONObject jo = arr.getJSONObject(i);
                        String key = jo.getString(keyNode);
-                       String value = jo.getString(valueNode);
+                       String value = jo.get(valueNode).toString();
                        map.put(key, value);
                }
                msoLogger.debug("Completed Entry Array To Map Util Method");
index 6748128..067ae98 100644 (file)
@@ -81,7 +81,19 @@ public class JsonUtilsTest {
                JSONArray assignmentInfo = homingDataJson.getJSONArray("assignmentInfo");
                Map<String, String> map = utils.entryArrayToMap(assignmentInfo.toString(), "variableName", "variableValue");
                assertEquals(map.get("cloudOwner"), "CloudOwner");
-       }       
+       }
+       @Test
+       public void entryArrayToMapStringTestOof() throws IOException {
+               JsonUtils utils = new JsonUtils();
+               String response = this.getJson("OofExample.json");
+               String entry = JsonUtils.getJsonValue(response, "solutions.placementSolutions");
+               JSONArray arr = new JSONArray(entry);
+               JSONArray arr2 = arr.getJSONArray(0);
+               JSONObject homingDataJson = arr2.getJSONObject(0);
+               JSONArray assignmentInfo = homingDataJson.getJSONArray("assignmentInfo");
+               Map<String, String> map = utils.entryArrayToMap(assignmentInfo.toString(), "key", "value");
+               assertEquals(map.get("cloudOwner"), "HPA-cloud");
+       }
        @Test
        public void getJsonRootPropertyTest() throws IOException {
                String response = this.getJson("SDNCServiceResponseExample.json");
diff --git a/bpmn/MSOCoreBPMN/src/test/resources/json-examples/OofExample.json b/bpmn/MSOCoreBPMN/src/test/resources/json-examples/OofExample.json
new file mode 100644 (file)
index 0000000..127748a
--- /dev/null
@@ -0,0 +1,110 @@
+{
+  "requestStatus":"completed",
+  "statusMessage":"",
+  "solutions":{
+    "placementSolutions":[
+      [
+        {
+          "serviceResourceId":"78976677-bca7-446a-8b31-52b83e9aa925",
+          "resourceModuleName":"7400fd06C75f4a44A68f",
+          "solution":{
+            "identifierType":"cloudRegionId",
+            "cloudOwner":"HPA-cloud",
+            "identifiers":[
+              "Cloud-region3"
+            ]
+          },
+          "assignmentInfo":[
+            {
+              "value":"false",
+              "key":"isRehome"
+            },
+            {
+              "value":"att_aic",
+              "key":"locationType"
+            },
+            {
+              "value":"Cloud-region3",
+              "key":"locationId"
+            },
+            {
+              "value":{
+                "directives":[
+                  {
+                    "directives":[
+                      {
+                        "attributes":[
+                          {
+                            "attribute_value":"Flavor31",
+                            "attribute_name":"label_1"
+                          }
+                        ],
+                        "type":"flavor_directives"
+                      },
+                      {
+                        "attributes":[
+                          {
+                            "attribute_value":"direct",
+                            "attribute_name":"oof_returned_vnic_type_for_firewall_protected"
+                          }
+                        ],
+                        "type":"sriovNICNetwork_directives"
+                      }
+                    ],
+                    "type":"vnfc",
+                    "id":"vfw_1"
+                  },
+                  {
+                    "directives":[
+                      {
+                        "attributes":[
+                          {
+                            "attribute_value":"Flavor32",
+                            "attribute_name":"label_2"
+                          }
+                        ],
+                        "type":"flavor_directives"
+                      }
+                    ],
+                    "type":"vnfc",
+                    "id":"vfw_2"
+                  },
+                  {
+                    "directives":[
+                      {
+                        "attributes":[
+                          {
+                            "attribute_value":"Flavor32",
+                            "attribute_name":"label_3"
+                          }
+                        ],
+                        "type":"flavor_directives"
+                      }
+                    ],
+                    "type":"vnfc",
+                    "id":"vfw_3"
+                  }
+                ]
+              },
+              "key":"oof_directives"
+            },
+            {
+              "value":"DLLSTX233",
+              "key":"cloudClli"
+            },
+            {
+              "value":"75919",
+              "key":"aic_version"
+            },
+            {
+              "value":"HPA-cloud",
+              "key":"cloudOwner"
+            }
+          ]
+        }
+      ]
+    ]
+  },
+  "transactionId":"",
+  "requestId":"05da4f90-15f7-4128-8ac4-e06dc3cc06f9"
+}
\ No newline at end of file
index 9763960..848785e 100755 (executable)
@@ -165,6 +165,10 @@ public class CreateGenericALaCarteServiceInstance extends AbstractServiceTaskPro
                             msoLogger.debug("User Input Parameter " + userParam.name + ": " + userParam.value.toString())
                             inputMap.put(userParam.name, userParam.value)
                         }
+                        if ("Orchestrator".equalsIgnoreCase(userParam?.name)) {
+                            execution.setVariable("orchestrator", userParam.value)
+                            inputMap.put("orchestrator", userParam.value)
+                        }
                 }
             }
 
@@ -344,6 +348,10 @@ public class CreateGenericALaCarteServiceInstance extends AbstractServiceTaskPro
                              msoLogger.debug("User Input Parameter " + userParam.name + ": " + userParam.value.toString())
                              inputMap.put(userParam.name, userParam.value)
                          }
+                         if ("Orchestrator".equalsIgnoreCase(userParam?.name)) {
+                             execution.setVariable("orchestrator", userParam.value)
+                             inputMap.put("orchestrator", userParam.value)
+                         }
                  }
              }
 
index 1a47ef8..187189c 100644 (file)
@@ -250,6 +250,10 @@ public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
                                     execution.setVariable("callHoming", true)
                                     inputMap.put("Homing_Solution", userParam.value)
                                 }
+                        if ("Orchestrator".equalsIgnoreCase(userParam?.name)) {
+                            execution.setVariable("orchestrator", userParam.value)
+                            inputMap.put("orchestrator", userParam.value)
+                        }
                 }
             }
 
index b1c81cf..e6d02c6 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.db.catalog.beans;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.openpojo.business.annotation.BusinessKey;
 import org.apache.commons.lang3.builder.HashCodeBuilder;
+
 import java.util.Date;
 
 import org.apache.commons.lang3.builder.EqualsBuilder;
index 4f070e7..8a61102 100644 (file)
@@ -590,7 +590,6 @@ public class CatalogDbClient {
                this.postSingleResource(cloudSiteClient, cloudSite);
        }
 
-
        public CloudSite getCloudSiteByClliAndAicVersion (String clli, String cloudVersion){
                return this.getSingleResource(cloudSiteClient, getUri(UriBuilder
                                .fromUri(findByClliAndCloudVersion)