ae239d9e685240c828d7d7fcdc70ac712cf73ec1
[so.git] /
1 package org.onap.so.bpmn.infrastructure.scripts
2
3
4 import org.onap.so.bpmn.core.domain.AllottedResource
5 import org.onap.aai.domain.yang.AllottedResource
6
7 import static org.apache.commons.lang3.StringUtils.*;
8
9 import org.camunda.bpm.engine.delegate.BpmnError
10 import org.camunda.bpm.engine.delegate.DelegateExecution
11 import org.onap.aai.domain.yang.OwningEntity
12 import org.onap.aai.domain.yang.ServiceProfile;
13 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
14 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
15 import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
16 import org.onap.so.bpmn.common.scripts.ExceptionUtil
17 import org.onap.so.bpmn.common.scripts.MsoUtils
18 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
19 import org.onap.so.bpmn.core.RollbackData
20 import org.onap.so.bpmn.core.UrnPropertiesReader
21 import org.onap.so.bpmn.core.WorkflowException
22 import org.onap.so.bpmn.core.domain.ModelInfo
23 import org.onap.so.bpmn.core.domain.ServiceDecomposition
24 import org.onap.so.bpmn.core.domain.ServiceInstance
25 import org.onap.so.bpmn.core.json.JsonUtils
26 import org.onap.so.bpmn.infrastructure.aai.groovyflows.AAICreateResources
27 import org.onap.so.client.aai.AAIObjectType
28 import org.onap.so.client.aai.AAIResourcesClient
29 import org.onap.so.client.aai.entities.uri.AAIResourceUri
30 import org.onap.so.client.aai.entities.uri.AAIUri
31 import org.onap.so.client.aai.entities.uri.AAIUriFactory
32 import org.slf4j.Logger
33 import org.slf4j.LoggerFactory
34
35
36
37 class DoCreateSliceServiceInstance extends AbstractServiceTaskProcessor{
38
39     private static final Logger logger = LoggerFactory.getLogger( DoCreateSliceServiceInstance.class);
40     JsonUtils jsonUtil = new JsonUtils()
41
42     ExceptionUtil exceptionUtil = new ExceptionUtil()
43
44     CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
45
46     /**
47      * Pre Process the BPMN Flow Request
48      * Inclouds:
49      * generate the nsOperationKey
50      * generate the nsParameters
51      */
52     void preProcessRequest (DelegateExecution execution) {
53         String msg = ""
54         logger.trace("Enter preProcessRequest()")
55         //Need update
56         //1. Prepare service parameter.
57         //2. Prepare slice profile parameters.
58
59         String sliceserviceInstanceId = execution.getVariable("serviceInstanceId")
60         String allottedResourceId = UUID.randomUUID().toString()
61         execution.setVariable("sliceserviceInstanceId", sliceserviceInstanceId)
62         execution.setVariable("allottedResourceId", allottedResourceId)
63
64         String uuiRequest = execution.getVariable("uuiRequest")
65         String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
66         String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
67         //here modelVersion is not set, we use modelUuid to decompose the service.
68         def isDebugLogEnabled = true
69         execution.setVariable("serviceInstanceId",sliceserviceInstanceId)
70         execution.setVariable("isDebugLogEnabled",isDebugLogEnabled)
71         String serviceModelInfo = """{
72             "modelInvariantUuid":"${modelInvariantUuid}",
73             "modelUuid":"${modelUuid}",
74             "modelVersion":""
75              }"""
76         execution.setVariable("serviceModelInfo", serviceModelInfo)
77
78         logger.trace("Exit preProcessRequest")
79     }
80
81
82     void createServiceProfile(DelegateExecution execution) {
83
84         String sliceserviceInstanceId = execution.getVariable("sliceserviceInstanceId")
85         Map<String, Object> serviceProfileMap = execution.getVariable("serviceProfile")
86         String serviceProfileID = UUID.randomUUID().toString()
87         ServiceProfile serviceProfile = new ServiceProfile();
88         serviceProfile.setProfileId(serviceProfileID)
89         serviceProfile.setLatency(Integer.parseInt(serviceProfileMap.get("latency").toString()))
90         serviceProfile.setMaxNumberOfUEs(Integer.parseInt(serviceProfileMap.get("maxNumberofUEs").toString()))
91         serviceProfile.setCoverageAreaTAList(serviceProfileMap.get("coverageAreaTAList").toString())
92         serviceProfile.setUeMobilityLevel(serviceProfileMap.get("uEMobilityLevel").toString())
93         serviceProfile.setResourceSharingLevel(serviceProfileMap.get("resourceSharingLevel").toString())
94         serviceProfile.setExpDataRateUL(Integer.parseInt(serviceProfileMap.get("expDataRateUL").toString()))
95         serviceProfile.setExpDataRateDL(Integer.parseInt(serviceProfileMap.get("expDataRateDL").toString()))
96         serviceProfile.setAreaTrafficCapUL(Integer.parseInt(serviceProfileMap.get("areaTrafficCapUL").toString()))
97         serviceProfile.setAreaTrafficCapDL(Integer.parseInt(serviceProfileMap.get("areaTrafficCapDL").toString()))
98         serviceProfile.setActivityFactor(Integer.parseInt(serviceProfileMap.get("activityFactor").toString()))
99
100         serviceProfile.setJitter(0)
101         serviceProfile.setSurvivalTime(0)
102         serviceProfile.setCsAvailability(new Object())
103         serviceProfile.setReliability(new Object())
104         serviceProfile.setExpDataRate(0)
105         serviceProfile.setTrafficDensity(0)
106         serviceProfile.setConnDensity(0)
107         try {
108             AAIResourcesClient client = new AAIResourcesClient()
109             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_PROFILE, execution.getVariable("globalSubscriberId"),
110                     execution.getVariable("subscriptionServiceType"), sliceserviceInstanceId, serviceProfileID)
111             client.create(uri, serviceProfile)
112
113         } catch (BpmnError e) {
114             throw e
115         } catch (Exception ex) {
116             String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
117             logger.info(msg)
118             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
119         }
120     }
121
122     void instantiateSliceService(DelegateExecution execution) {
123
124         ServiceDecomposition serviceDecomposition= execution.getVariable("sliceServiceDecomposition")
125         String uuiRequest = execution.getVariable("uuiRequest")
126         ModelInfo modelInfo = serviceDecomposition.getModelInfo()
127         String serviceRole = "e2eslice-service"
128         String serviceType = execution.getVariable("serviceType")
129         Map<String, Object> serviceProfile = execution.getVariable("serviceProfile")
130         String ssInstanceId = execution.getVariable("serviceInstanceId")
131         try {
132             org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
133             ss.setServiceInstanceId(ssInstanceId)
134             String sliceInstanceName = execution.getVariable("serviceInstanceName")
135             ss.setServiceInstanceName(sliceInstanceName)
136             ss.setServiceType(serviceType)
137             String serviceStatus = "deactivated"
138             ss.setOrchestrationStatus(serviceStatus)
139             String modelInvariantUuid = modelInfo.getModelInvariantUuid()
140             String modelUuid = modelInfo.getModelUuid()
141             ss.setModelInvariantId(modelInvariantUuid)
142             ss.setModelVersionId(modelUuid)
143             String serviceInstanceLocationid = serviceProfile.get("plmnIdList")
144             ss.setServiceInstanceLocationId(serviceInstanceLocationid)
145             String snssai = serviceProfile.get("sNSSAI")
146             ss.setEnvironmentContext(snssai)
147             ss.setServiceRole(serviceRole)
148             AAIResourcesClient client = new AAIResourcesClient()
149             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), ssInstanceId)
150             client.create(uri, ss)
151         } catch (BpmnError e) {
152             throw e
153         } catch (Exception ex) {
154             String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
155             logger.info(msg)
156             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
157         }
158
159
160         def rollbackData = execution.getVariable("RollbackData")
161         if (rollbackData == null) {
162             rollbackData = new RollbackData();
163         }
164         //rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
165         rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
166         rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", ssInstanceId)
167         rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
168         rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
169         execution.setVariable("rollbackData", rollbackData)
170         execution.setVariable("RollbackData", rollbackData)
171         logger.debug("RollbackData:" + rollbackData)
172
173     }
174
175
176     void createAllottedResource(DelegateExecution execution) {
177         String serviceInstanceId = execution.getVariable('sliceserviceInstanceId')
178
179         AAIResourcesClient resourceClient = new AAIResourcesClient()
180         AAIResourceUri ssServiceuri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
181
182 //        try {
183 //
184 //            if(resourceClient.exists(ssServiceuri)){
185 //                execution.setVariable("ssi_resourceLink", uri.build().toString())
186 //            }else{
187 //                exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai to " +
188 //                        "associate allotted resource for service :"+serviceInstanceId)
189 //            }
190 //        }catch(BpmnError e) {
191 //            throw e;
192 //        }catch (Exception ex){
193 //            String msg = "Exception in getServiceInstance. " + ex.getMessage()
194 //            logger.debug(msg)
195 //            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
196 //        }
197
198         try {
199             String allottedResourceId = execution.getVariable("allottedResourceId")
200             ServiceDecomposition serviceDecomposition = execution.getVariable("sliceServiceDecomposition")
201             List<org.onap.so.bpmn.core.domain.AllottedResource> allottedResourceList = serviceDecomposition.getAllottedResources()
202             for(org.onap.so.bpmn.core.domain.AllottedResource allottedResource : allottedResourceList)
203             {
204                 //AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceFromParentURI(ssServiceuri, AAIObjectType.ALLOTTED_RESOURCE, allottedResourceId)
205                 AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE,
206                         execution.getVariable("globalSubscriberId"),execution.getVariable("subscriptionServiceType"),
207                         execution.getVariable("sliceserviceInstanceId"), allottedResourceId)
208                 execution.setVariable("allottedResourceUri", allottedResourceUri)
209                 String arType = allottedResource.getAllottedResourceType()
210                 String arRole = allottedResource.getAllottedResourceRole()
211                 String modelInvariantId = allottedResource.getModelInfo().getModelInvariantUuid()
212                 String modelVersionId = allottedResource.getModelInfo().getModelUuid()
213
214                 org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
215                 resource.setId(allottedResourceId)
216                 resource.setType(arType)
217                 resource.setAllottedResourceName("Allotted_"+ execution.getVariable("serviceInstanceName"))
218                 resource.setRole(arRole)
219                 resource.setModelInvariantId(modelInvariantId)
220                 resource.setModelVersionId(modelVersionId)
221                 getAAIClient().create(allottedResourceUri, resource)
222                 //AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath(ssServiceuri).build())
223                 //getAAIClient().connect(allottedResourceUri,ssServiceuri)
224             }
225             //execution.setVariable("aaiARPath", allottedResourceUri.build().toString());
226
227         }catch (Exception ex) {
228             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in createAaiAR " + ex.getMessage())
229         }
230     }
231
232 }