2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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;
44 import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
46 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION;
47 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL;
48 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL_VF_MODULE;
49 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL_VM;
50 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL_VNF;
51 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ACTION_LEVEL_VNFC;
52 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_CONTENTS;
53 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION;
54 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_NAME;
55 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_NAME_CAPABILITY;
56 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_NAME_REFERENCE;
57 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_TYPE;
58 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_UUID;
59 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ARTIFACT_VERSION;
60 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.CAPABILITY;
61 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG;
62 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION;
63 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL;
64 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE;
65 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DB_SDC_REFERENCE;
66 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
67 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DISTRIBUTION_ID;
68 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS;
69 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE;
70 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.FILE_CATEGORY;
71 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE;
72 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE;
73 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.TEMPLATE_ID;
74 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP;
75 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.PARAMETER_YANG;
76 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.PD;
77 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.PORT_NUMBER;
78 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.REFERENCE;
79 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.REQUEST_INFORMATION;
80 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.REQUEST_ID;
81 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME;
82 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_TYPE;
83 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_UUID;
84 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_VERSION;
85 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.SERVICE_DESCRIPTION;
86 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.SERVICE_NAME;
87 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.SERVICE_UUID;
88 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.TEMPLATE;
89 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.TOSCA_MODEL;
90 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.USER_NAME;
91 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VM;
92 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VM_INSTANCE;
93 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC;
94 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE;
95 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE_LIST;
96 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC_INSTANCE;
97 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNFC_TYPE;
98 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNF_TYPE;
100 public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
102 private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerNode.class);
104 public void processArtifact(Map<String, String> inParams, SvcLogicContext ctx) throws Exception {
105 if (inParams == null || inParams.isEmpty()) {
108 String postData = inParams.get("postData");
109 if (postData == null || postData.isEmpty()) {
113 log.info("Received request for process Artifact with params: " + inParams.toString());
114 JSONObject input = new JSONObject(postData).getJSONObject("input");
115 String responsePrefix = inParams.get("response_prefix");
116 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
117 storeUpdateSdcArtifacts(input);
118 } catch (Exception e) {
119 log.error("Error when processing artifact", e);
120 throw new ArtifactProcessorException("Error occurred while processing artifact", e);
124 private boolean storeUpdateSdcArtifacts(JSONObject postDataJson) throws ArtifactHandlerInternalException {
125 log.info("Starting processing of SDC Artifacs into Handler with Data : " + postDataJson.toString());
127 JSONObject request_information =
128 (JSONObject) postDataJson.get(REQUEST_INFORMATION);
129 JSONObject document_information =
130 (JSONObject) postDataJson.get(DOCUMENT_PARAMETERS);
131 String artifact_name = document_information.getString(ARTIFACT_NAME);
132 if (artifact_name != null) {
133 updateStoreArtifacts(request_information, document_information);
134 if (artifact_name.toLowerCase().startsWith(REFERENCE)) {
135 return storeReferenceData(request_information, document_information);
136 } else if (artifact_name.toLowerCase().startsWith(PD)) {
137 return createDataForPD(request_information, document_information);
141 throw new ArtifactHandlerInternalException("Missing Artifact Name for Request: "
142 + request_information.getString(REQUEST_ID));
144 } catch (Exception e) {
145 log.error("Error while processing request with id: "
146 + ((JSONObject) postDataJson.get(REQUEST_INFORMATION))
147 .getString(REQUEST_ID), e);
149 throw new ArtifactHandlerInternalException("Error while processing request with id: "
150 + ((JSONObject) postDataJson.get(REQUEST_INFORMATION))
151 .getString(REQUEST_ID), e);
157 private boolean createDataForPD(JSONObject request_information, JSONObject document_information)
158 throws ArtifactHandlerInternalException {
160 String fn = "ArtifactHandlerNode.createReferenceDataForPD";
161 String artifact_name = document_information.getString(ARTIFACT_NAME);
162 log.info(fn + "Received PD File Name: " + artifact_name + " and suffix lenght "
166 String suffix = artifact_name.substring(PD.length());
167 createArtifactRecords(request_information, document_information, suffix);
168 } catch (Exception e) {
169 log.error("Error while creating PD data records", e);
170 throw new ArtifactHandlerInternalException("Error while creating PD data records", e);
175 private void createArtifactRecords(JSONObject request_information, JSONObject document_information, String suffix)
176 throws ArtifactHandlerInternalException {
179 log.info("Creating Tosca Records and storing into SDC Artifacs");
180 String[] docs = {"Tosca", "Yang"};
181 ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
182 String PDFileContents = document_information.getString(ARTIFACT_CONTENTS);
185 OutputStream toscaStream = new ByteArrayOutputStream();
186 String toscaContents = null;
187 ArtifactProcessorImpl toscaGenerator = new ArtifactProcessorImpl();
188 toscaGenerator.generateArtifact(PDFileContents, toscaStream);
189 toscaContents = toscaStream.toString();
190 log.info("Generated Tosca File : " + toscaContents);
192 String yangContents = "YANG generation is in Progress";
193 String yangName = null;
195 for (String doc : docs) {
196 document_information.put(ARTIFACT_TYPE, doc.concat("Type"));
197 document_information.put(ARTIFACT_DESRIPTION, doc.concat("Model"));
198 if (doc.equals("Tosca")) {
199 document_information.put(ARTIFACT_CONTENTS,
200 ahpUtil.escapeSql(toscaContents));
201 } else if (doc.equals("Yang")) {
202 document_information.put(ARTIFACT_CONTENTS,
203 ahpUtil.escapeSql(yangContents));
205 document_information.put(ARTIFACT_NAME, doc.concat(suffix));
206 yangName = doc.concat(suffix);
207 updateStoreArtifacts(request_information, document_information);
210 String artifactId = getArtifactID(yangName);
211 OutputStream yangStream = new ByteArrayOutputStream();
212 YANGGenerator yangGenerator = YANGGeneratorFactory.getYANGGenerator();
213 yangGenerator.generateYANG(artifactId, toscaContents, yangStream);
214 yangContents = yangStream.toString();
216 if (yangContents != null) {
217 updateYangContents(artifactId, ahpUtil.escapeSql(yangContents));
220 } catch (Exception e) {
221 log.error("Error while creating artifact records", e);
222 throw new ArtifactHandlerInternalException("Error while creating artifact records", e);
227 private void updateYangContents(String artifactId, String yangContents) throws SvcLogicException {
228 SvcLogicContext context = new SvcLogicContext();
229 DBService dbservice = DBService.initialise();
230 dbservice.updateYangContents(context, artifactId, yangContents);
233 private String getArtifactID(String yangName) throws SvcLogicException {
234 SvcLogicContext context = new SvcLogicContext();
235 DBService dbservice = DBService.initialise();
236 return dbservice.getArtifactID(context, yangName);
239 protected boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information)
240 throws SvcLogicException {
241 log.info("UpdateStoreArtifactsStarted storing of SDC Artifacs ");
243 SvcLogicContext context = new SvcLogicContext();
244 DBService dbservice = DBService.initialise();
245 ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
247 context.setAttribute("artifact_name",
248 document_information.getString(ARTIFACT_NAME));
249 String internal_version = dbservice.getInternalVersionNumber(context,
250 document_information.getString(ARTIFACT_NAME), null);
251 log.info("Internal Version number received from Database : " + internal_version);
252 if (internal_version != null) {
253 intversion = Integer.parseInt(internal_version);
257 setAttribute(context, document_information::getString, SERVICE_UUID);
258 setAttribute(context, document_information::getString, DISTRIBUTION_ID);
259 setAttribute(context, document_information::getString, SERVICE_NAME);
260 setAttribute(context, document_information::getString, SERVICE_DESCRIPTION);
261 setAttribute(context, document_information::getString, RESOURCE_UUID);
262 setAttribute(context, document_information::getString, RESOURCE_INSTANCE_NAME);
263 setAttribute(context, document_information::getString, RESOURCE_VERSION);
264 setAttribute(context, document_information::getString, RESOURCE_TYPE);
265 setAttribute(context, document_information::getString, ARTIFACT_UUID);
266 setAttribute(context, document_information::getString, ARTIFACT_TYPE);
267 setAttribute(context, document_information::getString, ARTIFACT_VERSION);
268 setAttribute(context, document_information::getString, ARTIFACT_DESRIPTION);
269 setAttribute(context, document_information::getString, ARTIFACT_NAME);
271 setAttribute(context, s -> ahpUtil.escapeSql(document_information.getString(s)), ARTIFACT_CONTENTS);
273 dbservice.saveArtifacts(context, intversion);
278 public boolean storeReferenceData(JSONObject request_information, JSONObject document_information)
279 throws ArtifactHandlerInternalException {
280 log.info("Started storing of SDC Artifacs into Handler");
282 boolean updateRequired = false;
283 boolean pdFile = false;
284 String suffix = null;
285 String categorySuffix = null;
286 DBService dbservice = DBService.initialise();
287 ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
288 String contentString =
289 ahpUtil.escapeSql(document_information.getString(ARTIFACT_CONTENTS));
290 String artifactName =
291 ahpUtil.escapeSql(document_information.getString(ARTIFACT_NAME));
292 String capabilityArtifactName =
293 StringUtils.replace(artifactName, ARTIFACT_NAME_REFERENCE,
294 ARTIFACT_NAME_CAPABILITY);
295 JSONObject capabilities = new JSONObject();
296 JSONArray vnfActionList = new JSONArray();
297 JSONArray vfModuleActionList = new JSONArray();
298 JSONArray vnfcActionList = new JSONArray();
299 JSONArray vmActionVnfcFunctionCodesList = new JSONArray();
300 JSONArray vmActionList = new JSONArray();
301 String vnfType = null;
302 JSONObject contentObject = new JSONObject(contentString);
303 JSONArray contentArray = contentObject.getJSONArray("reference_data");
304 boolean storeCapabilityArtifact = true;
305 for (int a = 0; a < contentArray.length(); a++) {
307 JSONObject content = (JSONObject) contentArray.get(a);
308 log.info("contentString =" + content.toString());
309 JSONObject scope = content.getJSONObject("scope");
310 log.info("scope :" + scope);
311 SvcLogicContext context = new SvcLogicContext();
312 vnfType = scope.getString(VNF_TYPE);
313 setAttribute(context, scope::getString, VNF_TYPE);
314 setAttribute(context, content::getString, ACTION);
315 String actionLevel = content.getString(ACTION_LEVEL);
316 setAttribute(context, content::getString, ACTION_LEVEL);
317 setAttribute(context, document_information::getString, ARTIFACT_TYPE);
318 processActionLists(content, actionLevel, vnfcActionList, vfModuleActionList,vnfActionList, vmActionVnfcFunctionCodesList);
319 storeCapabilityArtifact=isCapabilityArtifactNeeded(scope, context);
320 if (content.has(DEVICE_PROTOCOL)) {
321 setAttribute(context, content::getString, DEVICE_PROTOCOL);
323 if (content.has(USER_NAME)) {
324 setAttribute(context, content::getString, USER_NAME);
326 if (content.has(PORT_NUMBER)) {
327 setAttribute(context, content::getString, PORT_NUMBER);
329 //context.setAttribute(ARTIFACT_TYPE, "");
330 processArtifactList(content,dbservice,context);
331 processConfigTypeActions(content,dbservice,context);
332 dbservice.processDeviceAuthentication(context,
333 dbservice.isArtifactUpdateRequired(context, DB_DEVICE_AUTHENTICATION));
335 populateProtocolReference(dbservice, content);
337 context.setAttribute(VNFC_TYPE, null);
340 && content.get(VM) instanceof JSONArray) {
341 processVmList(content, context, dbservice);
346 if (storeCapabilityArtifact) {
347 capabilities.put("vnf", vnfActionList);
348 capabilities.put("vf-module", vfModuleActionList);
349 capabilities.put("vnfc", vnfcActionList);
350 capabilities.put("vm", vmActionVnfcFunctionCodesList);
351 processAndStoreCapabilitiesArtifact(dbservice, document_information, capabilities,
352 capabilityArtifactName,
356 } catch (Exception e) {
358 log.error("Error while storing reference data", e);
359 throw new ArtifactHandlerInternalException("Error while storing reference data", e);
365 public boolean isCapabilityArtifactNeeded(JSONObject scope, SvcLogicContext context) {
366 boolean storeCapabilityArtifact=true;
367 if (scope.has(VNFC_TYPE)
368 && !scope.isNull(VNFC_TYPE)) {
369 String vnfcTypeScope = scope.getString(VNFC_TYPE);
370 if (StringUtils.isNotBlank(vnfcTypeScope)) {
371 setAttribute(context, scope::getString, VNFC_TYPE);
372 storeCapabilityArtifact = false;
373 log.info("No capability Artifact for this reference data as it is at VNFC level!!");
375 context.setAttribute(VNFC_TYPE, null);
378 context.setAttribute(VNFC_TYPE, null);
380 return storeCapabilityArtifact;
383 public void processActionLists(JSONObject content, String actionLevel, JSONArray vnfcActionList, JSONArray vfModuleActionList,
384 JSONArray vnfActionList, JSONArray vmActionVnfcFunctionCodesList) {
385 if ((null != actionLevel)
386 && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VNFC)) {
387 vnfcActionList.put(content.getString(ACTION));
389 if (null != actionLevel
390 && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VF_MODULE)) {
391 vfModuleActionList.put(content.getString(ACTION));
393 if (null != actionLevel && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VNF)) {
394 vnfActionList.put(content.getString(ACTION));
396 if (null != actionLevel && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VM)) {
397 if (content.has(VNFC_FUNCTION_CODE_LIST)
398 && !content.isNull(VNFC_FUNCTION_CODE_LIST) && content.get(
399 VNFC_FUNCTION_CODE_LIST) instanceof JSONArray) {
400 log.info("Found vnfc-function-code-list!!");
401 JSONArray vnfcList = content.getJSONArray(VNFC_FUNCTION_CODE_LIST);
402 JSONObject obj = new JSONObject();
403 obj.put(content.getString(ACTION), vnfcList);
404 vmActionVnfcFunctionCodesList.put(obj);
406 log.info("Not getting JSONArray for VNFC FUNCTION CODES");
412 public void processArtifactList(JSONObject content, DBService dbservice, SvcLogicContext context) throws Exception {
413 boolean pdFile = false;
414 String suffix = null;
415 String categorySuffix = null;
416 if (content.has("artifact-list") && content.get("artifact-list") instanceof JSONArray) {
417 JSONArray artifactLists = (JSONArray) content.get("artifact-list");
418 for (int i = 0; i < artifactLists.length(); i++) {
419 JSONObject artifact = (JSONObject) artifactLists.get(i);
420 log.info("artifact is " + artifact);
421 setAttribute(context, artifact::getString, ARTIFACT_NAME);
422 context.setAttribute(FILE_CATEGORY,
423 artifact.getString(ARTIFACT_TYPE));
425 if (artifact.getString(ARTIFACT_NAME) != null
426 && artifact.getString(ARTIFACT_NAME).toLowerCase()
428 suffix = artifact.getString(ARTIFACT_NAME)
429 .substring(PD.length());
430 categorySuffix = artifact.getString(ARTIFACT_TYPE)
431 .substring(PD.length());
434 log.info("Artifact-type = " + context.getAttribute(ARTIFACT_TYPE));
435 dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context,
438 cleanArtifactInstanceData(context);
442 context.setAttribute(ARTIFACT_NAME, "Tosca".concat(suffix));
443 context.setAttribute(FILE_CATEGORY, TOSCA_MODEL);
444 dbservice.processSdcReferences(context,
445 dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
446 context.setAttribute(ARTIFACT_NAME, "Yang".concat(suffix));
447 context.setAttribute(FILE_CATEGORY, PARAMETER_YANG);
448 dbservice.processSdcReferences(context,
449 dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
455 public void processConfigTypeActions(JSONObject content, DBService dbservice, SvcLogicContext context)throws Exception {
456 if (content.getString(ACTION).equals("Configure")
457 || content.getString(ACTION).equals("ConfigModify") || content.getString(ACTION).equals("ConfigScaleOut")) {
458 if (content.has(DOWNLOAD_DG_REFERENCE)
459 && content.getString(DOWNLOAD_DG_REFERENCE).length() > 0) {
460 setAttribute(context, content::getString, DOWNLOAD_DG_REFERENCE);
461 dbservice.processDownloadDgReference(context,
462 dbservice.isArtifactUpdateRequired(context, DB_DOWNLOAD_DG_REFERENCE));
464 if (StringUtils.isBlank(context.getAttribute(DOWNLOAD_DG_REFERENCE))) {
465 context.setAttribute(DOWNLOAD_DG_REFERENCE,
466 dbservice.getDownLoadDGReference(context));
468 dbservice.processConfigActionDg(context, dbservice.isArtifactUpdateRequired(context,
469 DB_CONFIG_ACTION_DG));
470 if (content.getString(ACTION).equals("Configure") || content.getString(ACTION).equals("ConfigScaleOut")) {
471 boolean isPresent=dbservice.isArtifactUpdateRequired(context,DB_DEVICE_INTERFACE_PROTOCOL);
472 if (content.getString(ACTION).equals("Configure") || (content.getString(ACTION).equals("ConfigScaleOut") && !isPresent))
473 dbservice.processDeviceInterfaceProtocol(context, isPresent);
480 public void processVmList(JSONObject content, SvcLogicContext context, DBService dbservice) throws Exception{
481 JSONArray vmList = (JSONArray) content.get(VM);
482 dbservice.cleanUpVnfcReferencesForVnf(context);
483 for (int i = 0; i < vmList.length(); i++) {
484 JSONObject vmInstance = (JSONObject) vmList.get(i);
485 setAttribute(context, s -> String.valueOf(vmInstance.getInt(s)), VM_INSTANCE);
486 log.info("VALUE = " + context.getAttribute(VM_INSTANCE));
487 String templateId = vmInstance.optString(TEMPLATE_ID);
488 if (StringUtils.isNotBlank(templateId)) {
489 setAttribute(context, vmInstance::optString, TEMPLATE_ID);
491 if (vmInstance.get(VNFC) instanceof JSONArray) {
492 JSONArray vnfcInstanceList = (JSONArray) vmInstance.get(VNFC);
493 for (int k = 0; k < vnfcInstanceList.length(); k++) {
494 JSONObject vnfcInstance = (JSONObject) vnfcInstanceList.get(k);
496 setAttribute(context, s -> String.valueOf(vnfcInstance.getInt(s)), VNFC_INSTANCE);
497 setAttribute(context, vnfcInstance::getString, VNFC_TYPE);
498 setAttribute(context, vnfcInstance::getString, VNFC_FUNCTION_CODE);
500 if (vnfcInstance.has(IPADDRESS_V4_OAM_VIP)) {
501 setAttribute(context, vnfcInstance::getString, IPADDRESS_V4_OAM_VIP);
503 if (vnfcInstance.has(GROUP_NOTATION_TYPE)) {
504 setAttribute(context, vnfcInstance::getString, GROUP_NOTATION_TYPE);
506 if (vnfcInstance.has(GROUP_NOTATION_VALUE)) {
507 setAttribute(context, vnfcInstance::getString, GROUP_NOTATION_VALUE);
509 if (content.getString(ACTION).equals("Configure")
510 || content.getString(ACTION).equals("ConfigScaleOut")) {
511 dbservice.processVnfcReference(context, false);
513 cleanVnfcInstance(context);
515 context.setAttribute(VM_INSTANCE, null);
516 context.setAttribute(TEMPLATE_ID, null);
522 private void cleanArtifactInstanceData(SvcLogicContext context) {
523 context.setAttribute(ARTIFACT_NAME, null);
524 context.setAttribute(FILE_CATEGORY, null);
527 private void cleanVnfcInstance(SvcLogicContext context) {
529 context.setAttribute(VNFC_INSTANCE, null);
530 context.setAttribute(VNFC_TYPE, null);
531 context.setAttribute(VNFC_FUNCTION_CODE, null);
532 context.setAttribute(IPADDRESS_V4_OAM_VIP, null);
533 context.setAttribute(GROUP_NOTATION_TYPE, null);
534 context.setAttribute(GROUP_NOTATION_VALUE, null);
538 private void processAndStoreCapabilitiesArtifact(DBService dbservice, JSONObject document_information,
539 JSONObject capabilities, String capabilityArtifactName, String vnfType)
540 throws ArtifactHandlerInternalException {
542 log.info("Begin-->processAndStoreCapabilitiesArtifact ");
546 JSONObject newCapabilitiesObject = new JSONObject();
547 newCapabilitiesObject.put("capabilities", capabilities);
548 SvcLogicContext context = new SvcLogicContext();
549 context.setAttribute(ARTIFACT_NAME, capabilityArtifactName);
550 context.setAttribute(FILE_CATEGORY, CAPABILITY);
551 context.setAttribute(ACTION, null);
552 context.setAttribute(VNFC_TYPE, null);
553 context.setAttribute(ARTIFACT_TYPE, null);
554 context.setAttribute(VNF_TYPE, vnfType);
555 context.setAttribute(ARTIFACT_CONTENTS, newCapabilitiesObject.toString());
556 dbservice.processSdcReferences(context,
557 dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
560 String internal_version = dbservice.getInternalVersionNumber(context,
561 context.getAttribute(ARTIFACT_NAME), null);
562 log.info("Internal Version number received from Database : " + internal_version);
563 if (internal_version != null) {
564 intversion = Integer.parseInt(internal_version);
568 setAttribute(context, document_information::getString, SERVICE_UUID);
569 setAttribute(context, document_information::getString, DISTRIBUTION_ID);
570 setAttribute(context, document_information::getString, SERVICE_NAME);
571 setAttribute(context, document_information::getString, SERVICE_DESCRIPTION);
572 setAttribute(context, document_information::getString, RESOURCE_UUID);
573 setAttribute(context, document_information::getString, RESOURCE_INSTANCE_NAME);
574 setAttribute(context, document_information::getString, RESOURCE_VERSION);
575 setAttribute(context, document_information::getString, RESOURCE_TYPE);
576 setAttribute(context, document_information::getString, ARTIFACT_UUID);
577 setAttribute(context, document_information::getString, ARTIFACT_VERSION);
578 setAttribute(context, document_information::getString, ARTIFACT_DESRIPTION);
580 dbservice.saveArtifacts(context, intversion);
581 } catch (Exception e) {
582 log.error("Error saving capabilities artifact to DB", e);
583 throw new ArtifactHandlerInternalException("Error saving capabilities artifact to DB", e);
585 log.info("End-->processAndStoreCapabilitiesArtifact ");
590 private void setAttribute(SvcLogicContext context, Function<String, String> value, String key) {
591 context.setAttribute(key, value.apply(key));
594 private void populateProtocolReference(DBService dbservice, JSONObject content)
595 throws ArtifactHandlerInternalException {
596 log.info("Begin-->populateProtocolReference ");
598 SvcLogicContext context = new SvcLogicContext();
599 JSONObject scope = content.getJSONObject("scope");
600 String vnfType = null, protocol = null, action = null, actionLevel = null, template = null;
601 if (scope.has(VNF_TYPE) && !scope.isNull(VNF_TYPE)) {
602 vnfType = scope.getString(VNF_TYPE);
604 if (content.has(DEVICE_PROTOCOL)) {
605 protocol = content.getString(DEVICE_PROTOCOL);
607 if (content.has(ACTION)) {
608 action = content.getString(ACTION);
610 if (content.has(ACTION_LEVEL)) {
611 actionLevel = content.getString(ACTION_LEVEL);
613 if (content.has(TEMPLATE)
614 && !content.isNull(TEMPLATE)) {
615 template = content.getString(TEMPLATE);
617 boolean isUpdateNeeded = dbservice
618 .isProtocolReferenceUpdateRequired(context, vnfType, protocol, action, actionLevel, template);
619 if (isUpdateNeeded) {
620 dbservice.updateProtocolReference(context, vnfType, protocol, action, actionLevel, template);
622 dbservice.insertProtocolReference(context, vnfType, protocol, action, actionLevel, template);
624 } catch (Exception e) {
625 log.error("Error inserting record into protocolReference", e);
626 throw new ArtifactHandlerInternalException("Error inserting record into protocolReference", e);
628 log.info("End-->populateProtocolReference ");