2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.artifact.handler.node;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.apache.commons.lang.StringUtils;
30 import org.json.JSONArray;
31 import org.json.JSONObject;
32 import org.onap.appc.artifact.handler.dbservices.DBService;
33 import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtil;
34 import org.onap.appc.yang.YANGGenerator;
35 import org.onap.appc.yang.impl.YANGGeneratorFactory;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
39 import org.onap.sdnc.config.params.transformer.tosca.ArtifactProcessorImpl;
40 import java.io.ByteArrayOutputStream;
41 import java.io.OutputStream;
43 import java.util.function.Function;
45 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION;
46 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL;
47 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL_VF_MODULE;
48 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL_VM;
49 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL_VNF;
50 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL_VNFC;
51 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_CONTENTS;
52 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION;
53 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_NAME;
54 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_NAME_CAPABILITY;
55 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_NAME_REFERENCE;
56 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_TYPE;
57 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_UUID;
58 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_VERSION;
59 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.CAPABILITY;
60 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG;
61 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION;
62 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL;
63 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE;
64 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_SDC_REFERENCE;
65 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
66 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DISTRIBUTION_ID;
67 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS;
68 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE;
69 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.FILE_CATEGORY;
70 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE;
71 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE;
72 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP;
73 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.PARAMETER_YANG;
74 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.PD;
75 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.PORT_NUMBER;
76 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.REFERENCE;
77 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.REQUEST_INFORMATION;
78 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.REQUEST_ID;
79 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME;
80 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_TYPE;
81 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_UUID;
82 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_VERSION;
83 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.SERVICE_DESCRIPTION;
84 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.SERVICE_NAME;
85 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.SERVICE_UUID;
86 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.TEMPLATE;
87 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.TOSCA_MODEL;
88 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.USER_NAME;
89 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VM;
90 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VM_INSTANCE;
91 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC;
92 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE;
93 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE_LIST;
94 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC_INSTANCE;
95 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC_TYPE;
96 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNF_TYPE;
98 public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
100 private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerNode.class);
102 public void processArtifact(Map<String, String> inParams, SvcLogicContext ctx) throws Exception {
103 String responsePrefix = inParams.get("response_prefix");
105 if (inParams != null && !inParams.isEmpty() && inParams.get("postData") != null) {
106 log.info("Received request for process Artifact with params: " + inParams.toString());
107 String postData = inParams.get("postData");
108 JSONObject input = new JSONObject(postData).getJSONObject("input");
109 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
110 storeUpdateSdcArtifacts(input);
112 } catch (Exception e) {
118 private boolean storeUpdateSdcArtifacts(JSONObject postDataJson) throws Exception {
119 log.info("Starting processing of SDC Artifacs into Handler with Data : " + postDataJson.toString());
121 JSONObject request_information =
122 (JSONObject) postDataJson.get(REQUEST_INFORMATION);
123 JSONObject document_information =
124 (JSONObject) postDataJson.get(DOCUMENT_PARAMETERS);
125 String artifact_name = document_information.getString(ARTIFACT_NAME);
126 if (artifact_name != null) {
127 updateStoreArtifacts(request_information, document_information);
128 if (artifact_name.toLowerCase().startsWith(REFERENCE))
129 return storeReferenceData(request_information, document_information);
130 else if (artifact_name.toLowerCase().startsWith(PD))
131 return createDataForPD(request_information, document_information);
134 throw new Exception("Missing Artifact Name for Request : "
135 + request_information.getString(REQUEST_ID));
136 } catch (Exception e) {
138 throw new Exception("Error while processing Request ID : "
139 + ((JSONObject) postDataJson.get(REQUEST_INFORMATION))
140 .getString(REQUEST_ID)
147 private boolean createDataForPD(JSONObject request_information, JSONObject document_information) throws Exception {
149 String fn = "ArtifactHandlerNode.createReferenceDataForPD";
150 String artifact_name = document_information.getString(ARTIFACT_NAME);
151 log.info(fn + "Received PD File Name: " + artifact_name + " and suffix lenght "
155 String suffix = artifact_name.substring(PD.length());
156 createArtifactRecords(request_information, document_information, suffix);
157 } catch (Exception e) {
159 throw new Exception("Error while createing PD data records " + e.getMessage());
164 private void createArtifactRecords(JSONObject request_information, JSONObject document_information, String suffix)
167 log.info("Creating Tosca Records and storing into SDC Artifacs");
168 String[] docs = {"Tosca", "Yang"};
169 ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
170 String PDFileContents = document_information.getString(ARTIFACT_CONTENTS);
173 OutputStream toscaStream = new ByteArrayOutputStream();
174 String toscaContents = null;
175 ArtifactProcessorImpl toscaGenerator = new ArtifactProcessorImpl();
176 toscaGenerator.generateArtifact(PDFileContents, toscaStream);
177 if (toscaStream != null)
178 toscaContents = toscaStream.toString();
179 log.info("Generated Tosca File : " + toscaContents);
181 String yangContents = "YANG generation is in Progress";
182 String yangName = null;
184 for (String doc : docs) {
185 document_information.put(ARTIFACT_TYPE, doc.concat("Type"));
186 document_information.put(ARTIFACT_DESRIPTION, doc.concat("Model"));
187 if (doc.equals("Tosca"))
188 document_information.put(ARTIFACT_CONTENTS,
189 ahpUtil.escapeSql(toscaContents));
190 else if (doc.equals("Yang"))
191 document_information.put(ARTIFACT_CONTENTS,
192 ahpUtil.escapeSql(yangContents));
193 document_information.put(ARTIFACT_NAME, doc.concat(suffix));
194 yangName = doc.concat(suffix);
195 updateStoreArtifacts(request_information, document_information);
198 String artifactId = getArtifactID(yangName);
199 OutputStream yangStream = new ByteArrayOutputStream();
200 YANGGenerator yangGenerator = YANGGeneratorFactory.getYANGGenerator();
201 yangGenerator.generateYANG(artifactId, toscaContents, yangStream);
202 if (yangStream != null)
203 yangContents = yangStream.toString();
205 if (yangContents != null) {
206 updateYangContents(artifactId, ahpUtil.escapeSql(yangContents));
211 private void updateYangContents(String artifactId, String yangContents) throws SvcLogicException {
212 SvcLogicContext context = new SvcLogicContext();
213 DBService dbservice = DBService.initialise();
214 dbservice.updateYangContents(context, artifactId, yangContents);
217 private String getArtifactID(String yangName) throws SvcLogicException {
218 SvcLogicContext context = new SvcLogicContext();
219 DBService dbservice = DBService.initialise();
220 return dbservice.getArtifactID(context, yangName);
223 protected boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information)
225 log.info("UpdateStoreArtifactsStarted storing of SDC Artifacs ");
227 SvcLogicContext context = new SvcLogicContext();
228 DBService dbservice = DBService.initialise();
229 ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
231 context.setAttribute("artifact_name",
232 document_information.getString(ARTIFACT_NAME));
233 String internal_version = dbservice.getInternalVersionNumber(context,
234 document_information.getString(ARTIFACT_NAME), null);
235 log.info("Internal Version number received from Database : " + internal_version);
236 if (internal_version != null) {
237 intversion = Integer.parseInt(internal_version);
241 setAttribute(context, document_information::getString, SERVICE_UUID);
242 setAttribute(context, document_information::getString, DISTRIBUTION_ID);
243 setAttribute(context, document_information::getString, SERVICE_NAME);
244 setAttribute(context, document_information::getString, SERVICE_DESCRIPTION);
245 setAttribute(context, document_information::getString, RESOURCE_UUID);
246 setAttribute(context, document_information::getString, RESOURCE_INSTANCE_NAME);
247 setAttribute(context, document_information::getString, RESOURCE_VERSION);
248 setAttribute(context, document_information::getString, RESOURCE_TYPE);
249 setAttribute(context, document_information::getString, ARTIFACT_UUID);
250 setAttribute(context, document_information::getString, ARTIFACT_TYPE);
251 setAttribute(context, document_information::getString, ARTIFACT_VERSION);
252 setAttribute(context, document_information::getString, ARTIFACT_DESRIPTION);
253 setAttribute(context, document_information::getString, ARTIFACT_NAME);
255 setAttribute(context, s -> ahpUtil.escapeSql(document_information.getString(s)), ARTIFACT_CONTENTS);
257 dbservice.saveArtifacts(context, intversion);
262 public boolean storeReferenceData(JSONObject request_information, JSONObject document_information)
264 log.info("Started storing of SDC Artifacs into Handler");
266 boolean updateRequired = false;
267 boolean pdFile = false;
268 String suffix = null;
269 String categorySuffix = null;
270 DBService dbservice = DBService.initialise();
271 ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
272 String contentString =
273 ahpUtil.escapeSql(document_information.getString(ARTIFACT_CONTENTS));
274 String artifactName =
275 ahpUtil.escapeSql(document_information.getString(ARTIFACT_NAME));
276 String capabilityArtifactName =
277 StringUtils.replace(artifactName, ARTIFACT_NAME_REFERENCE,
278 ARTIFACT_NAME_CAPABILITY);
279 JSONObject capabilities = new JSONObject();
280 JSONArray vnfActionList = new JSONArray();
281 JSONArray vfModuleActionList = new JSONArray();
282 JSONArray vnfcActionList = new JSONArray();
283 JSONArray vmActionVnfcFunctionCodesList=new JSONArray();
284 JSONArray vmActionList = new JSONArray();
285 String vnfType = null;
286 JSONObject contentObject = new JSONObject(contentString);
287 JSONArray contentArray = contentObject.getJSONArray("reference_data");
288 boolean storeCapabilityArtifact = true;
289 for (int a = 0; a < contentArray.length(); a++) {
291 JSONObject content = (JSONObject) contentArray.get(a);
292 log.info("contentString =" + content.toString());
293 JSONObject scope = content.getJSONObject("scope");
294 log.info("scope :" + scope);
295 SvcLogicContext context = new SvcLogicContext();
296 vnfType = scope.getString(VNF_TYPE);
297 setAttribute(context, scope::getString, VNF_TYPE);
298 setAttribute(context, content::getString, ACTION);
299 String actionLevel = content.getString(ACTION_LEVEL);
300 setAttribute(context, content::getString, ACTION_LEVEL);
301 setAttribute(context, document_information::getString, ARTIFACT_TYPE);
302 if ((null != actionLevel)
303 && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VNFC)) {
304 vnfcActionList.put(content.getString(ACTION));
306 if (null != actionLevel
307 && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VF_MODULE)) {
308 vfModuleActionList.put(content.getString(ACTION));
310 if (null != actionLevel && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VNF)) {
311 vnfActionList.put(content.getString(ACTION));
313 if (null != actionLevel && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VM)) {
314 if (content.has(VNFC_FUNCTION_CODE_LIST)
315 && !content.isNull(VNFC_FUNCTION_CODE_LIST) && content.get(
316 VNFC_FUNCTION_CODE_LIST) instanceof JSONArray) {
317 log.info("Found vnfc-function-code-list!!");
318 JSONArray vnfcList = content.getJSONArray(VNFC_FUNCTION_CODE_LIST);
319 JSONObject obj = new JSONObject();
320 obj.put(content.getString(ACTION), vnfcList);
321 vmActionVnfcFunctionCodesList.put(obj);
323 log.info("Not getting JSONArray for VNFC FUNCTION CODES");
326 if (scope.has(VNFC_TYPE)
327 && !scope.isNull(VNFC_TYPE)) {
328 String vnfcTypeScope = scope.getString(VNFC_TYPE);
329 if (StringUtils.isNotBlank(vnfcTypeScope)) {
330 setAttribute(context, scope::getString, VNFC_TYPE);
331 storeCapabilityArtifact = false;
332 log.info("No capability Artifact for this reference data as it is at VNFC level!!");
335 context.setAttribute(VNFC_TYPE, null);
339 context.setAttribute(VNFC_TYPE, null);
340 if (content.has(DEVICE_PROTOCOL))
341 setAttribute(context, content::getString, DEVICE_PROTOCOL);
342 if (content.has(USER_NAME))
343 setAttribute(context, content::getString, USER_NAME);
344 if (content.has(PORT_NUMBER))
345 setAttribute(context, content::getString, PORT_NUMBER);
346 //context.setAttribute(ARTIFACT_TYPE, "");
347 if (content.has("artifact-list") && content.get("artifact-list") instanceof JSONArray) {
348 JSONArray artifactLists = (JSONArray) content.get("artifact-list");
349 for (int i = 0; i < artifactLists.length(); i++) {
350 JSONObject artifact = (JSONObject) artifactLists.get(i);
351 log.info("artifact is " + artifact);
352 setAttribute(context, artifact::getString, ARTIFACT_NAME);
353 context.setAttribute(FILE_CATEGORY,
354 artifact.getString(ARTIFACT_TYPE));
356 if (artifact.getString(ARTIFACT_NAME) != null
357 && artifact.getString(ARTIFACT_NAME).toLowerCase()
359 suffix = artifact.getString(ARTIFACT_NAME)
360 .substring(PD.length());
361 categorySuffix = artifact.getString(ARTIFACT_TYPE)
362 .substring(PD.length());
365 log.info("Artifact-type = " + context.getAttribute(ARTIFACT_TYPE));
366 dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context,
369 cleanArtifactInstanceData(context);
373 context.setAttribute(ARTIFACT_NAME, "Tosca".concat(suffix));
374 context.setAttribute(FILE_CATEGORY, TOSCA_MODEL);
375 dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
376 context.setAttribute(ARTIFACT_NAME, "Yang".concat(suffix));
377 context.setAttribute(FILE_CATEGORY, PARAMETER_YANG);
378 dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
381 if (content.getString(ACTION).equals("Configure")
382 || content.getString(ACTION).equals("ConfigModify")) {
383 if (content.has(DOWNLOAD_DG_REFERENCE)
384 && content.getString(DOWNLOAD_DG_REFERENCE).length() > 0) {
385 setAttribute(context, content::getString, DOWNLOAD_DG_REFERENCE);
386 dbservice.processDownloadDgReference(context, dbservice.isArtifactUpdateRequired(context, DB_DOWNLOAD_DG_REFERENCE));
388 if (StringUtils.isBlank(context.getAttribute(DOWNLOAD_DG_REFERENCE))) {
389 context.setAttribute(DOWNLOAD_DG_REFERENCE,
390 dbservice.getDownLoadDGReference(context));
392 dbservice.processConfigActionDg(context, dbservice.isArtifactUpdateRequired(context,
393 DB_CONFIG_ACTION_DG));
394 if (content.getString(ACTION).equals("Configure")) {
395 dbservice.processDeviceInterfaceProtocol(context, dbservice.isArtifactUpdateRequired(context,
396 DB_DEVICE_INTERFACE_PROTOCOL));
400 dbservice.processDeviceAuthentication(context, dbservice.isArtifactUpdateRequired(context, DB_DEVICE_AUTHENTICATION));
402 populateProtocolReference(dbservice, content);
404 context.setAttribute(VNFC_TYPE, null);
407 && content.get(VM) instanceof JSONArray) {
408 JSONArray vmList = (JSONArray) content.get(VM);
409 dbservice.cleanUpVnfcReferencesForVnf(context);
410 for (int i = 0; i < vmList.length(); i++) {
411 JSONObject vmInstance = (JSONObject) vmList.get(i);
412 setAttribute(context, s -> String.valueOf(vmInstance.getInt(s)), VM_INSTANCE);
413 log.info("VALUE = " + context.getAttribute(VM_INSTANCE));
414 if (vmInstance.get(VNFC) instanceof JSONArray) {
415 JSONArray vnfcInstanceList = (JSONArray) vmInstance.get(VNFC);
416 for (int k = 0; k < vnfcInstanceList.length(); k++) {
417 JSONObject vnfcInstance = (JSONObject) vnfcInstanceList.get(k);
419 setAttribute(context, s -> String.valueOf(vnfcInstance.getInt(s)), VNFC_INSTANCE);
420 setAttribute(context, vnfcInstance::getString, VNFC_TYPE);
421 setAttribute(context, vnfcInstance::getString, VNFC_FUNCTION_CODE);
423 if (vnfcInstance.has(IPADDRESS_V4_OAM_VIP))
424 setAttribute(context, vnfcInstance::getString, IPADDRESS_V4_OAM_VIP);
425 if (vnfcInstance.has(GROUP_NOTATION_TYPE))
426 setAttribute(context, vnfcInstance::getString, GROUP_NOTATION_TYPE);
427 if (vnfcInstance.has(GROUP_NOTATION_VALUE))
428 setAttribute(context, vnfcInstance::getString, GROUP_NOTATION_VALUE);
429 if (content.getString(ACTION).equals("Configure")) {
430 dbservice.processVnfcReference(context,false);
432 cleanVnfcInstance(context);
434 context.setAttribute(VM_INSTANCE, null);
441 if (storeCapabilityArtifact) {
442 capabilities.put("vnf", vnfActionList);
443 capabilities.put("vf-module", vfModuleActionList);
444 capabilities.put("vnfc", vnfcActionList);
445 capabilities.put("vm", vmActionVnfcFunctionCodesList);
446 processAndStoreCapabilitiesArtifact(dbservice, document_information, capabilities, capabilityArtifactName,
450 } catch (Exception e) {
452 throw new Exception("Error While Storing : " + e.getMessage());
458 private void cleanArtifactInstanceData(SvcLogicContext context) {
459 context.setAttribute(ARTIFACT_NAME, null);
460 context.setAttribute(FILE_CATEGORY, null);
463 private void cleanVnfcInstance(SvcLogicContext context) {
465 context.setAttribute(VNFC_INSTANCE, null);
466 context.setAttribute(VNFC_TYPE, null);
467 context.setAttribute(VNFC_FUNCTION_CODE, null);
468 context.setAttribute(IPADDRESS_V4_OAM_VIP, null);
469 context.setAttribute(GROUP_NOTATION_TYPE, null);
470 context.setAttribute(GROUP_NOTATION_VALUE, null);
474 private void processAndStoreCapabilitiesArtifact(DBService dbservice, JSONObject document_information,
475 JSONObject capabilities, String capabilityArtifactName, String vnfType) throws Exception {
476 log.info("Begin-->processAndStoreCapabilitiesArtifact ");
480 JSONObject newCapabilitiesObject = new JSONObject();
481 newCapabilitiesObject.put("capabilities", capabilities);
482 SvcLogicContext context = new SvcLogicContext();
483 context.setAttribute(ARTIFACT_NAME, capabilityArtifactName);
484 context.setAttribute(FILE_CATEGORY, CAPABILITY);
485 context.setAttribute(ACTION, null);
486 context.setAttribute(VNFC_TYPE, null);
487 context.setAttribute(ARTIFACT_TYPE, null);
488 context.setAttribute(VNF_TYPE, vnfType);
489 context.setAttribute(ARTIFACT_CONTENTS, newCapabilitiesObject.toString());
490 dbservice.processSdcReferences(context,
491 dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
494 String internal_version = dbservice.getInternalVersionNumber(context,
495 context.getAttribute(ARTIFACT_NAME), null);
496 log.info("Internal Version number received from Database : " + internal_version);
497 if (internal_version != null) {
498 intversion = Integer.parseInt(internal_version);
502 setAttribute(context, document_information::getString, SERVICE_UUID);
503 setAttribute(context, document_information::getString, DISTRIBUTION_ID);
504 setAttribute(context, document_information::getString, SERVICE_NAME);
505 setAttribute(context, document_information::getString, SERVICE_DESCRIPTION);
506 setAttribute(context, document_information::getString, RESOURCE_UUID);
507 setAttribute(context, document_information::getString, RESOURCE_INSTANCE_NAME);
508 setAttribute(context, document_information::getString, RESOURCE_VERSION);
509 setAttribute(context, document_information::getString, RESOURCE_TYPE);
510 setAttribute(context, document_information::getString, ARTIFACT_UUID);
511 setAttribute(context, document_information::getString, ARTIFACT_VERSION);
512 setAttribute(context, document_information::getString, ARTIFACT_DESRIPTION);
514 dbservice.saveArtifacts(context, intversion);
515 } catch (Exception e) {
516 log.error("Error saving capabilities artifact to DB: " + e.toString());
519 log.info("End-->processAndStoreCapabilitiesArtifact ");
524 private void setAttribute(SvcLogicContext context, Function<String, String> value, String key) {
525 context.setAttribute(key, value.apply(key));
528 private void populateProtocolReference(DBService dbservice, JSONObject content) throws Exception {
529 log.info("Begin-->populateProtocolReference ");
531 SvcLogicContext context = new SvcLogicContext();
532 JSONObject scope = content.getJSONObject("scope");
533 String vnfType = null, protocol = null, action = null, actionLevel = null, template = null;
534 if (scope.has(VNF_TYPE) && !scope.isNull(VNF_TYPE))
535 vnfType = scope.getString(VNF_TYPE);
536 if (content.has(DEVICE_PROTOCOL))
537 protocol = content.getString(DEVICE_PROTOCOL);
538 if (content.has(ACTION))
539 action = content.getString(ACTION);
540 if (content.has(ACTION_LEVEL))
541 actionLevel = content.getString(ACTION_LEVEL);
542 if (content.has(TEMPLATE)
543 && !content.isNull(TEMPLATE))
544 template = content.getString(TEMPLATE);
545 boolean isUpdateNeeded=dbservice.isProtocolReferenceUpdateRequired(context, vnfType, protocol, action, actionLevel, template);
547 dbservice.updateProtocolReference(context, vnfType, protocol, action, actionLevel, template);
549 dbservice.insertProtocolReference(context, vnfType,protocol,action,actionLevel,template);
550 } catch (Exception e) {
551 log.error("Error inserting record into protocolReference: " + e.toString());
554 log.info("End-->populateProtocolReference ");