Add DoCompareModelVersions.groovy 93/35693/1
authorYulian Han <elaine.hanyulian@huawei.com>
Mon, 12 Mar 2018 11:59:53 +0000 (19:59 +0800)
committerYulian Han <elaine.hanyulian@huawei.com>
Wed, 14 Mar 2018 08:05:41 +0000 (16:05 +0800)
Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f0641ca
Issue-ID: SO-419
Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCompareModelVersions.groovy [new file with mode: 0644]

diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCompareModelVersions.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCompareModelVersions.groovy
new file mode 100644 (file)
index 0000000..a8af52a
--- /dev/null
@@ -0,0 +1,255 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. \r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.openecomp.mso.bpmn.infrastructure.scripts;\r
+\r
+import static org.apache.commons.lang3.StringUtils.*;\r
+import groovy.xml.XmlUtil\r
+import groovy.json.*\r
+\r
+import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition\r
+import org.openecomp.mso.bpmn.core.domain.ServiceInstance\r
+import org.openecomp.mso.bpmn.core.domain.ModelInfo\r
+import org.openecomp.mso.bpmn.core.domain.Resource\r
+import org.openecomp.mso.bpmn.core.domain.AllottedResource\r
+import org.openecomp.mso.bpmn.core.domain.NetworkResource\r
+import org.openecomp.mso.bpmn.core.domain.VnfResource\r
+import org.openecomp.mso.bpmn.common.recipe.ResourceInput\r
+import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient\r
+import org.openecomp.mso.bpmn.core.json.JsonUtils\r
+import org.openecomp.mso.bpmn.common.scripts.AaiUtil\r
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
+import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils\r
+import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;\r
+import org.openecomp.mso.bpmn.core.RollbackData\r
+import org.openecomp.mso.bpmn.core.WorkflowException\r
+import org.openecomp.mso.rest.APIResponse;\r
+import org.openecomp.mso.rest.RESTClient\r
+import org.openecomp.mso.rest.RESTConfig\r
+\r
+import java.util.List;\r
+import java.util.UUID;\r
+\r
+import javax.mail.Quota.Resource;\r
+\r
+import org.camunda.bpm.engine.delegate.BpmnError\r
+import org.camunda.bpm.engine.runtime.Execution\r
+import org.json.JSONObject;\r
+import org.json.JSONArray;\r
+import org.apache.commons.lang3.*\r
+import org.apache.commons.codec.binary.Base64;\r
+import org.springframework.web.util.UriUtils;\r
+\r
+/**\r
+ * This groovy class supports the <class>DoCompareModelVersions.bpmn</class> process.\r
+ *\r
+ * Inputs:\r
+ * @param - model-invariant-id-target\r
+ * @param - model-version-id-target\r
+ * @param - model-invariant-id-original\r
+ * @param - model-version-id-original\r
+ *\r
+ * Outputs:\r
+ * @param - addResourceList\r
+ * @param - delResourceList\r
+ *\r
+ */\r
+public class DoCompareModelVersions extends AbstractServiceTaskProcessor {\r
+\r
+       String Prefix="DCMPMDV_"\r
+       ExceptionUtil exceptionUtil = new ExceptionUtil()\r
+       JsonUtils jsonUtil = new JsonUtils()\r
+       CatalogDbUtils cutils = new CatalogDbUtils()\r
+\r
+       public void preProcessRequest (Execution execution) {\r
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+               String msg = ""\r
+               utils.log("INFO"," ***** preProcessRequest *****",  isDebugEnabled)\r
+\r
+               try {\r
+                       execution.setVariable("prefix", Prefix)\r
+                       \r
+                       //Inputs\r
+                       String modelInvariantUuid_target = execution.getVariable("model-invariant-id-target")\r
+                       if (isBlank(modelInvariantUuid_target)) {\r
+                               msg = "Input model-invariant-id-target is null"\r
+                               utils.log("INFO", msg, isDebugEnabled)\r
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
+                       }                       \r
+                       \r
+            String modelUuid_target = execution.getVariable("model-version-id-target")\r
+            if (isBlank(modelUuid_target)) {\r
+                               msg = "Input model-version-id-target is null"\r
+                               utils.log("INFO", msg, isDebugEnabled)\r
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
+                       }\r
+            \r
+            String modelInvariantUuid_original = execution.getVariable("model-invariant-id-original")\r
+            if (isBlank(modelInvariantUuid_original)) {\r
+                               msg = "Input model-invariant-id-original is null"\r
+                               utils.log("INFO", msg, isDebugEnabled)\r
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
+                       }\r
+            \r
+            String modelUuid_original = execution.getVariable("model-version-id-original")\r
+            if (isBlank(modelUuid_original)) {\r
+                               msg = "Input model-version-id-original is null"\r
+                               utils.log("INFO", msg, isDebugEnabled)\r
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
+                       }  \r
+                       \r
+                       // Target and original modelInvariantUuid must to be the same\r
+                       if(modelInvariantUuid_target != modelInvariantUuid_original){\r
+                               msg = "Input model-invariant-id-target and model-invariant-id-original must to be the same"\r
+                               utils.log("INFO", msg, isDebugEnabled)\r
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)      \r
+                       }\r
+                       \r
+                       // Target and original modelUuid must not to be the same\r
+                       if(modelUuid_target == modelUuid_original){\r
+                               msg = "Input model-version-id-target and model-version-id-original must not to be the same"\r
+                               utils.log("INFO", msg, isDebugEnabled)\r
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)      \r
+                       }\r
+\r
+               } catch (Exception ex){\r
+                       msg = "Exception in preProcessRequest " + ex.getMessage()\r
+                       utils.log("INFO", msg, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+               }\r
+               utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
+       }\r
+       \r
+   public void prepareDecomposeService_Target(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+\r
+        try {\r
+            utils.log("DEBUG", " ***** Inside prepareDecomposeService_Target of update generic e2e service ***** ", isDebugEnabled)\r
+            String modelInvariantUuid = execution.getVariable("model-invariant-id-target")\r
+            String modelUuid = execution.getVariable("model-version-id-target")\r
+            //here modelVersion is not set, we use modelUuid to decompose the service.\r
+            String serviceModelInfo = """{\r
+            "modelInvariantUuid":"${modelInvariantUuid}",\r
+            "modelUuid":"${modelUuid}",\r
+            "modelVersion":""\r
+             }"""\r
+            execution.setVariable("serviceModelInfo", serviceModelInfo)\r
+            execution.setVariable("serviceModelInfo_Target", serviceModelInfo)\r
+\r
+            utils.log("DEBUG", " ***** Completed prepareDecomposeService_Target of update generic e2e service ***** ", isDebugEnabled)\r
+        } catch (Exception ex) {\r
+            // try error in method block\r
+            String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Target() - " + ex.getMessage()\r
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
+        }\r
+     }\r
+\r
+    public void processDecomposition_Target(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+    \r
+        utils.log("DEBUG", " ***** Inside processDecomposition_Target() of update generic e2e service flow ***** ", isDebugEnabled)    \r
+        try {\r
+            ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
+            execution.setVariable("serviceDecomposition_Target", serviceDecomposition)\r
+        } catch (Exception ex) {\r
+            String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method processDecomposition_Target() - " + ex.getMessage()\r
+            utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
+        }\r
+    }\r
\r
+   public void prepareDecomposeService_Original(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+\r
+        try {\r
+            utils.log("DEBUG", " ***** Inside prepareDecomposeService_Original of update generic e2e service ***** ", isDebugEnabled)\r
+            String modelInvariantUuid = execution.getVariable("model-invariant-id-original")\r
+            String modelUuid = execution.getVariable("model-version-id-original")\r
+            //here modelVersion is not set, we use modelUuid to decompose the service.\r
+            String serviceModelInfo = """{\r
+            "modelInvariantUuid":"${modelInvariantUuid}",\r
+            "modelUuid":"${modelUuid}",\r
+            "modelVersion":""\r
+             }"""\r
+            execution.setVariable("serviceModelInfo", serviceModelInfo)\r
+            execution.setVariable("serviceModelInfo_Original", serviceModelInfo)\r
+\r
+            utils.log("DEBUG", " ***** Completed prepareDecomposeService_Original of update generic e2e service ***** ", isDebugEnabled)\r
+        } catch (Exception ex) {\r
+            // try error in method block\r
+            String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Original() - " + ex.getMessage()\r
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
+        }\r
+     }\r
+\r
+    public void processDecomposition_Original(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+    \r
+        utils.log("DEBUG", " ***** Inside processDecomposition_Original() of update generic e2e service flow ***** ", isDebugEnabled)    \r
+        try {\r
+            ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
+            execution.setVariable("serviceDecomposition_Original", serviceDecomposition)\r
+        } catch (Exception ex) {\r
+            String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. processDecomposition_Original() - " + ex.getMessage()\r
+            utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
+        }\r
+    }  \r
+\r
+       public void doCompareModelVersions(execution){\r
+           def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO", "======== Start doCompareModelVersions Process ======== ", isDebugEnabled)          \r
+\r
+        ServiceDecomposition serviceDecomposition_Target = execution.getVariable("serviceDecomposition_Target")\r
+        ServiceDecomposition serviceDecomposition_Original = execution.getVariable("serviceDecomposition_Original")\r
+        \r
+        List<Resource> allSR_target = serviceDecomposition_Target.getServiceResources();\r
+        List<Resource> allSR_original = serviceDecomposition_Original.getServiceResources();\r
+        \r
+        List<Resource> addedResource = new ArrayList<String>()\r
+        List<Resource> delResource = new ArrayList<String>()\r
+        \r
+        addResourceList.addAll(allSR_target)\r
+        delResourceList.addAll(allSR_original)\r
+        \r
+        //Compare\r
+        for (Resource rc_t : allSR_target){\r
+            String muuid = rc_t.getModelInfo().getModelUuid()\r
+            String mIuuid = rc_t.getModelInfo().getModelInvariantUuid()\r
+            String mCuuid = rc_t.getModelInfo().getModelCustomizationUuid()\r
+            for (Resource rc_o : allSR_original){\r
+                if(rc_o.getModelInfo().getModelUuid() == muuid \r
+                && rc_o.getModelInfo().getModelInvariantUuid() == mIuuid \r
+                && rc_o.getModelInfo().getModelCustomizationUuid() == mCuuid) {\r
+                    addResourceList.remove(rc_t);\r
+                    delResourceList.remove(rc_o);\r
+                }\r
+            }         
+        }
+\r
+        execution.setVariable("addResourceList", addResourceList)\r
+        execution.setVariable("delResourceList", delResourceList)\r
+        utils.log("INFO", "addResourceList: " + addResourceList, isDebugEnabled)  \r
+        utils.log("INFO", "delResourceList: " + delResourceList, isDebugEnabled)\r
+        \r
+        utils.log("INFO", "======== COMPLETED doCompareModelVersions Process ======== ", isDebugEnabled)  \r
+       }\r
+\r
+}\r