Add Relationship for e2e service and NS 83/20883/1
authorc00149107 <chenchuanyu@huawei.com>
Fri, 27 Oct 2017 02:44:46 +0000 (10:44 +0800)
committerc00149107 <chenchuanyu@huawei.com>
Fri, 27 Oct 2017 02:44:46 +0000 (10:44 +0800)
Add Relationship for e2e service and NS

Change-Id: Id1bf6862b9d2325297e466d417dc1b169e157ff6
Issue-ID:SO-275
Signed-off-by: c00149107 <chenchuanyu@huawei.com>
adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiUtil.java [deleted file]
adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy
bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateVFCNetworkServiceInstance.bpmn

diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiUtil.java
deleted file mode 100644 (file)
index 7f1a6da..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.mso.adapters.vfc;
-
-import org.openecomp.mso.adapters.vfc.model.RestfulResponse;
-
-/**
- * Implement class of operating aai database table <br>
- * <p>
- * </p>
- * 
- * @author
- * @version ONAP Amsterdam Release 2017-08-28
- */
-public class AaiUtil {
-
-  public static RestfulResponse addRelation(String globalSubsriberId, String serviceType,
-      String serviceInstanceId, String resourceInstanceId) {
-    // sent rest to aai to add relation for service and ns.
-      
-    return null;
-  }
-
-  public static RestfulResponse removeRelation(String globalSubsriberId, String serviceType,
-      String serviceInstanceId, String resourceInstanceId) {
-    // sent rest to aai to remove relation between service an ns.
-    return null;
-  }
-}
index 94f4de3..35c8ead 100644 (file)
@@ -137,12 +137,7 @@ public class VfcManager {
           DriverExceptionID.INVALID_RESPONSEE_FROM_CREATE_OPERATION);
     }
     LOGGER.info("create ns -> end");
-    LOGGER.info("save segment and operaton info -> begin");
-    // Step 6: add relation between service and NS
-    AaiUtil.addRelation(segInput.getNsOperationKey().getGlobalSubscriberId(),
-        segInput.getNsOperationKey().getServiceType(), segInput.getNsOperationKey().getServiceId(),
-        nsInstanceId);
-    LOGGER.info("save segment and operation info -> end");
+
     return createRsp;
   }
 
@@ -181,11 +176,6 @@ public class VfcManager {
           DriverExceptionID.FAIL_TO_DELETE_NS);
     }
 
-    // Step3: remove relation info between service and ns
-    AaiUtil.removeRelation(nsOperationKey.getGlobalSubscriberId(), nsOperationKey.getServiceType(),
-        nsOperationKey.getServiceId(), nsInstanceId);
-    LOGGER.info("delete segment information -> end");
-
     // Step4: update service segment operation status
     nsOperInfo.setStatus(RequestsDbConstant.Status.FINISHED);
     nsOperInfo.setErrorCode(String.valueOf(deleteRsp.getStatus()));
index 8354798..2e62abd 100644 (file)
@@ -53,7 +53,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
     ExceptionUtil exceptionUtil = new ExceptionUtil()\r
 \r
     JsonUtils jsonUtil = new JsonUtils()\r
-\r
+    \r
     /**\r
      * Pre Process the BPMN Flow Request\r
      * Inclouds:\r
@@ -118,7 +118,8 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
      * create NS task\r
      */\r
     public void createNetworkService(Execution execution) {\r
-        \r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO"," *****  createNetworkService *****",  isDebugEnabled)\r
         String nsOperationKey = execution.getVariable("nsOperationKey");\r
         String nsParameters = execution.getVariable("nsParameters");\r
         String nsServiceName = execution.getVariable("nsServiceName")\r
@@ -137,13 +138,15 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
             nsInstanceId =  jsonUtil.getJsonValue(aaiResponseAsString, "nsInstanceId")\r
         }\r
         execution.setVariable("nsInstanceId", nsInstanceId)\r
-        \r
+        utils.log("INFO"," *****Exit  createNetworkService *****",  isDebugEnabled)\r
     }\r
 \r
     /**\r
      * instantiate NS task\r
      */\r
     public void instantiateNetworkService(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO"," *****  instantiateNetworkService *****",  isDebugEnabled)\r
         String nsOperationKey = execution.getVariable("nsOperationKey");\r
         String nsParameters = execution.getVariable("nsParameters");\r
         String nsServiceName = execution.getVariable("nsServiceName")\r
@@ -163,13 +166,16 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
         if(returnCode== "200"){\r
             jobId =  jsonUtil.getJsonValue(aaiResponseAsString, "jobId")\r
         }\r
-        execution.setVariable("jobId", nsInstanceId)\r
+        execution.setVariable("jobId", jobId)\r
+        utils.log("INFO"," *****Exit  instantiateNetworkService *****",  isDebugEnabled)\r
     }\r
 \r
     /**\r
      * query NS task\r
      */\r
     public void queryNSProgress(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO"," *****  queryNSProgress *****",  isDebugEnabled)\r
         String jobId = execution.getVariable("jobId")\r
         String nsOperationKey = execution.getVariable("nsOperationKey");\r
         String url = host + vfcUrl + "/jobs/" + jobId\r
@@ -181,24 +187,81 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
             operationStatus = jsonUtil.getJsonValue(aaiResponseAsString, "responseDescriptor.status")\r
         }\r
         execution.setVariable("operationStatus", operationStatus)\r
+        utils.log("INFO"," *****Exit  queryNSProgress *****",  isDebugEnabled)\r
     }\r
 \r
     /**\r
      * delay 5 sec \r
      */\r
     public void timeDelay(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
         try {\r
             Thread.sleep(5000);\r
         } catch(InterruptedException e) {           \r
-            taskProcessor.utils.log("ERROR", "Time Delay exception" + e , isDebugEnabled)\r
+            utils.log("ERROR", "Time Delay exception" + e , isDebugEnabled)\r
         }\r
     }\r
 \r
     /**\r
      * finish NS task\r
      */\r
-    public void finishNSCreate(Execution execution) {\r
-        //no need to do anything util now\r
+    public void addNSRelationship(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO"," ***** addNSRelationship *****",  isDebugEnabled)\r
+        String operationStatus = execution.getVariable("operationStatus")\r
+        if(operationStatus != "finished"){\r
+            utils.log("INFO"," create NS failed, so do not need to add relationship",  isDebugEnabled)\r
+            return\r
+        }\r
+        String globalSubscriberId = execution.getVariable("globalSubscriberId")\r
+        String serviceType = execution.getVariable("serviceType")\r
+        String serviceId = execution.getVariable("serviceId")\r
+        String nsInstanceId = execution.getVariable("nsInstanceId")\r
+        String addRelationPayload = """<relationship xmlns="http://org.openecomp.aai.inventory/v11">\r
+                                            <related-to>service-instance</related-to>\r
+                                            <related-link>/aai/v11/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${nsInstanceId}</related-link>\r
+                                            <relationship-data>\r
+                                                <relationship-key>customer.global-customer-id</relationship-key>\r
+                                                <relationship-value>${globalSubscriberId}</relationship-value>\r
+                                            </relationship-data>\r
+                                            <relationship-data>\r
+                                                <relationship-key>service-subscription.service-type</relationship-key>\r
+                                                <relationship-value>${serviceType}</relationship-value>\r
+                                            </relationship-data>\r
+                                           <relationship-data>\r
+                                                <relationship-key>service-instance.service-instance-id</relationship-key>\r
+                                                <relationship-value>${nsInstanceId}</relationship-value>\r
+                                            </relationship-data>           \r
+                                        </relationship>"""\r
+        String endpoint = execution.getVariable("URN_aai_endpoint")  \r
+        String url = endpoint + "/aai/v11/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances/service-instance/" + serviceId + "/relationship-list/relationship"\r
+        executeAAIPutCall(execution, url, addRelationPayload)\r
+        utils.log("INFO"," *****Exit addNSRelationship *****",  isDebugEnabled)\r
+    }\r
+    \r
+    public APIResponse executeAAIPutCall(Execution execution, String url, String payload){\r
+        def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO", " ======== Started Execute AAI Put Process ======== ",  isDebugEnabled) \r
+        APIResponse apiResponse = null\r
+        try{\r
+            String uuid = utils.getRequestID()\r
+            utils.log("INFO","Generated uuid is: " + uuid,  isDebugEnabled) \r
+            utils.log("INFO","URL to be used is: " + url,  isDebugEnabled) \r
+            String userName = execution.getVariable("URN_aai_auth")\r
+            String password = execution.getVariable("URN_mso_msoKey")\r
+            String basicAuthCred = utils.getBasicAuth(userName,password)\r
+            RESTConfig config = new RESTConfig(url);\r
+            RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/xml").addHeader("Accept","application/xml");\r
+            if (basicAuthCred != null && !"".equals(basicAuthCred)) {\r
+                client.addAuthorizationHeader(basicAuthCred)\r
+            }\r
+            apiResponse = client.httpPut(payload)\r
+            utils.log("INFO","======== Completed Execute AAI Put Process ======== ",  isDebugEnabled) \r
+        }catch(Exception e){\r
+            utils.log("ERROR","Exception occured while executing AAI Put Call. Exception is: \n" + e,  isDebugEnabled) \r
+            throw new BpmnError("MSOWorkflowException")\r
+        }\r
+        return apiResponse\r
     }\r
     \r
     /**\r
index ffe9dca..67b0f96 100644 (file)
@@ -80,12 +80,12 @@ dcsi.instantiateNetworkService(execution)]]></bpmn:script>
 def dcsi = new DoCreateVFCNetworkServiceInstance()
 dcsi.queryNSProgress(execution)]]></bpmn:script>
     </bpmn:scriptTask>
-    <bpmn:scriptTask id="finishNSCreate_Task" name="Finish NS Create">
+    <bpmn:scriptTask id="finishNSCreate_Task" name="Add NS RelationShip" scriptFormat="groovy">
       <bpmn:incoming>operationFinished_SequenceFlow</bpmn:incoming>
       <bpmn:outgoing>SequenceFlow_0cq2q6g</bpmn:outgoing>
       <bpmn:script><![CDATA[import org.openecomp.mso.bpmn.infrastructure.scripts.*
 def dcsi = new DoCreateVFCNetworkServiceInstance()
-dcsi.finishNSCreate(execution)]]></bpmn:script>
+dcsi.addNSRelationship(execution)]]></bpmn:script>
     </bpmn:scriptTask>
     <bpmn:sequenceFlow id="SequenceFlow_0xqo13p" sourceRef="queryJob_Task" targetRef="ExclusiveGateway_15492gl" />
     <bpmn:scriptTask id="timeDelay_Task" name="timeDelay" scriptFormat="groovy">