05bb53a61e386cd7a2566b97671831dc7c75e336
[so.git] /
1 package org.onap.so.bpmn.infrastructure.scripts
2
3 import com.fasterxml.jackson.databind.ObjectMapper
4 import org.apache.commons.lang3.StringUtils
5 import org.camunda.bpm.engine.delegate.DelegateExecution
6 import org.onap.so.beans.nsmf.SliceTaskInfo
7 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
8 import org.onap.so.bpmn.common.scripts.ExceptionUtil
9 import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils
10 import org.onap.so.bpmn.core.domain.ModelInfo
11 import org.onap.so.bpmn.core.domain.ServiceDecomposition
12 import org.onap.so.bpmn.core.json.JsonUtils
13 import org.slf4j.Logger
14 import org.slf4j.LoggerFactory
15
16 class DoAllocateNSSIV2 extends AbstractServiceTaskProcessor {
17
18     private static final Logger logger = LoggerFactory.getLogger( DoAllocateNSSIV2.class);
19     private static final ObjectMapper MAPPER = new ObjectMapper();
20
21     ExceptionUtil exceptionUtil = new ExceptionUtil()
22
23     JsonUtils jsonUtil = new JsonUtils()
24
25     private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
26
27     @Override
28     void preProcessRequest(DelegateExecution execution) {
29         logger.trace("Enter preProcessRequest()")
30
31 //        String nssmfOperation
32 //
33 //        String nsstInput = execution.getVariable("nsstInput")
34 //        String modelUuid = jsonUtil.getJsonValue(nsstInput, "modelUuid")
35 //        //modelUuid="2763777c-27bd-4df7-93b8-c690e23f4d3f"
36 //        String nssiInstanceId = jsonUtil.getJsonValue(nsstInput, "serviceInstanceId")
37 //        String serviceModelInfo = """{
38 //            "modelInvariantUuid":"",
39 //            "modelUuid":"${modelUuid}",
40 //            "modelVersion":""
41 //             }"""
42 //        execution.setVariable("serviceModelInfo", serviceModelInfo)
43 //        execution.setVariable("nssiInstanceId", nssiInstanceId)
44 //        String nssiProfileID = UUID.randomUUID().toString()
45 //        execution.setVariable("nssiProfileID", nssiProfileID)
46 //        if(isBlank(nssiInstanceId))
47 //        {
48 //            nssmfOperation="create"
49 //            nssiInstanceId = UUID.randomUUID().toString()
50 //        }else {
51 //            nssmfOperation = "update"
52 //        }
53 //        execution.setVariable("nssmfOperation",nssmfOperation)
54 //        execution.setVariable("nssiInstanceId",nssiInstanceId)
55 //
56 //        def isNSSICreated = false
57 //        execution.setVariable("isNSSICreated",isNSSICreated)
58 //
59 //        int currentCycle = 0
60 //        execution.setVariable("currentCycle", currentCycle)
61
62
63         SliceTaskInfo sliceTaskInfo = execution.getVariable("sliceTaskInfo") as SliceTaskInfo
64         if (StringUtils.isBlank(sliceTaskInfo.suggestNssiId)) {
65             execution.setVariable("nssmfOperation", "create")
66         } else {
67             execution.setVariable("nssmfOperation", "update")
68         }
69         logger.trace("Exit preProcessRequest")
70     }
71
72     /**
73      * prepare nssi request
74      * @param execution
75      */
76     void prepareNSSIReq(DelegateExecution execution) {
77
78     }
79
80     void getNSSTInfo(DelegateExecution execution){
81         logger.trace("Enter getNSSTInfo in DoAllocateNSSI()")
82         ServiceDecomposition serviceDecomposition= execution.getVariable("serviceDecomposition")
83         ModelInfo modelInfo = serviceDecomposition.getModelInfo()
84         String serviceRole = "nssi"
85         String nssiServiceInvariantUuid = serviceDecomposition.modelInfo.getModelInvariantUuid()
86         String nssiServiceUuid = serviceDecomposition.modelInfo.getModelUuid()
87         String nssiServiceType = serviceDecomposition.getServiceType()
88         String uuiRequest = execution.getVariable("uuiRequest")
89         String nssiServiceName = "nssi_"+jsonUtil.getJsonValue(uuiRequest, "service.name")
90         execution.setVariable("nssiServiceName",nssiServiceName)
91         execution.setVariable("nssiServiceType",nssiServiceType)
92         execution.setVariable("nssiServiceInvariantUuid",nssiServiceInvariantUuid)
93         execution.setVariable("nssiServiceUuid",nssiServiceUuid)
94         execution.setVariable("serviceRole",serviceRole)
95
96         String content = serviceDecomposition.getServiceInfo().getServiceArtifact().get(0).getContent()
97         String nsstID = jsonUtil.getJsonValue(content, "metadata.id")
98         String nsstVendor = jsonUtil.getJsonValue(content, "metadata.vendor")
99         String nsstDomain = jsonUtil.getJsonValue(content, "metadata.domainType")
100         String nsstType = jsonUtil.getJsonValue(content, "metadata.type")
101
102         execution.setVariable("nsstID",nsstID)
103         execution.setVariable("nsstVendor",nsstVendor)
104         execution.setVariable("nsstDomain",nsstDomain)
105         execution.setVariable("nssiServiceUuid",nssiServiceUuid)
106         execution.setVariable("nsstType",nsstType)
107
108         String nsstContentInfo = """{
109         "NsstID":"${nsstID}",
110         "Vendor":"${nsstVendor}",
111         "type":"${nsstType}"
112          }"""
113
114         logger.trace("Exit getNSSTInfo in DoAllocateNSSI()")
115     }
116
117 }