2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.appc.data.services.node;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
27 import org.apache.commons.lang3.StringUtils;
28 import org.onap.appc.data.services.AppcDataServiceConstant;
29 import org.onap.appc.data.services.db.DGGeneralDBService;
30 import org.onap.appc.data.services.utils.EscapeUtils;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
37 import com.fasterxml.jackson.databind.JsonNode;
38 import com.fasterxml.jackson.databind.ObjectMapper;
40 public class ConfigResourceNode implements SvcLogicJavaPlugin {
42 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
44 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
46 log.info("Received getConfigFiles call with params : " + inParams);
48 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
52 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
53 DGGeneralDBService db = DGGeneralDBService.initialise();
54 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig",
55 "device_configuration");
57 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
58 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
60 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success",
61 "configuration_success");
63 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
64 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
66 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure",
67 "configuration_error");
69 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
70 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
72 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log");
74 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
75 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
78 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
79 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
80 log.info("GetConfigFileReference Successful ");
81 } catch (Exception e) {
82 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
83 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
84 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
85 log.error("Failed in GetConfigFileReference " + e.getMessage());
87 throw new SvcLogicException(e.getMessage());
91 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
93 log.info("Received getDeviceInfo call with params : " + inParams);
95 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
99 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
100 DGGeneralDBService db = DGGeneralDBService.initialise();
102 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
104 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
105 throw new Exception("Unable to Read device_interface_protocol");
107 status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
108 if (status == QueryStatus.FAILURE)
109 throw new Exception("Unable to Read configure_action_dg");
111 if (status == QueryStatus.NOT_FOUND) {
112 status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");
114 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
115 throw new Exception("Unable to Read configure_action_dg");
120 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
121 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
122 log.info("getCommonConfigInfo Successful ");
123 } catch (Exception e) {
124 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
125 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
126 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
127 log.error("Failed in getCommonConfigInfo " + e.getMessage());
129 throw new SvcLogicException(e.getMessage());
134 // fileCategory Can be config_template, parameter_definitions, parameter_yang
135 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
137 log.info("Received getTemplate call with params : " + inParams);
140 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
141 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
142 String templateName = ctx.getAttribute("template-name");
143 QueryStatus status = null;
144 String responsePrefix1 = "";
148 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
149 log.info("RESPONSEPREFIX : " + responsePrefix);
150 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
152 DGGeneralDBService db = DGGeneralDBService.initialise();
154 if (StringUtils.isBlank(templateName)) {
156 // if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
159 status = db.getTemplate(ctx, responsePrefix, fileCategory);
160 if (status == QueryStatus.FAILURE)
161 throw new Exception("Unable to Read " + fileCategory);
164 if (status == QueryStatus.NOT_FOUND) {
167 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
169 if (status == QueryStatus.FAILURE)
170 throw new Exception("Unable to Read " + fileCategory);
172 if (status == QueryStatus.NOT_FOUND) {
174 // status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
176 // if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
177 throw new Exception("Unable to Read " + fileCategory);
182 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
184 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
185 throw new Exception("Unable to Read " + fileCategory + " template");
189 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
190 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
191 log.info("GetTemplate Successful ");
192 } catch (Exception e) {
193 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
194 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
195 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
196 log.error("Failed in getTemplate " + e.getMessage());
198 throw new SvcLogicException(e.getMessage());
202 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
204 log.info("Received saveConfigFiles call with params : " + inParams);
206 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
210 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
211 DGGeneralDBService db = DGGeneralDBService.initialise();
212 QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
214 if (status == QueryStatus.FAILURE)
215 throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
217 status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
219 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
220 throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
222 status = db.savePrepareRelationship(ctx, "tmp.preparerel",
223 ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
224 if (status == QueryStatus.FAILURE)
225 throw new Exception("Unable to save prepare_relationship");
227 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
228 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
229 log.info("saveConfigFiles Successful ");
230 } catch (Exception e) {
231 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
232 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
233 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
234 log.error("Failed in saveConfigFiles " + e.getMessage());
236 throw new SvcLogicException(e.getMessage());
240 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
242 log.info("Received updateUploadConfig call with params : " + inParams);
244 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
248 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
249 DGGeneralDBService db = DGGeneralDBService.initialise();
251 ctx.setAttribute("tmp.escaped.devicerunningconfig",
252 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
254 QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
256 if (status == QueryStatus.FAILURE)
257 throw new Exception("Unable to Save configuration in upload_config");
259 status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
261 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
262 throw new Exception("Unable to get record from upload_config");
264 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
265 Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
266 if (status == QueryStatus.FAILURE)
267 throw new Exception("Unable to upload upload_config");
269 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
270 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
271 log.info("updateUploadConfig Successful ");
272 } catch (Exception e) {
273 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
274 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
275 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
276 log.error("Failed in updateUploadConfig " + e.getMessage());
278 throw new SvcLogicException(e.getMessage());
282 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
284 log.info("Received savePrepareRelationship call with params : " + inParams);
286 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
287 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
288 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
291 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
292 DGGeneralDBService db = DGGeneralDBService.initialise();
294 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
295 if (status == QueryStatus.FAILURE)
296 throw new Exception("Unable to save prepare_relationship");
298 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
299 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
300 log.info("savePrepareRelationship Successful ");
301 } catch (Exception e) {
302 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
303 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
304 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
305 log.error("Failed in saveConfigFiles " + e.getMessage());
307 throw new SvcLogicException(e.getMessage());
311 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
313 log.info("Received saveConfigBlock call with params : " + inParams);
315 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
319 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
320 ctx.setAttribute("tmp.convertconfig.escapeData", EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
321 DGGeneralDBService db = DGGeneralDBService.initialise();
323 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
324 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
325 ctx.getAttribute("configuration"));
328 saveConfigurationBlock(inParams, ctx);
330 ctx.setAttribute("tmp.convertconfig.escapeData",
331 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
332 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
333 ctx.getAttribute("tmp.merge.mergedData"));
335 saveConfigurationData(inParams, ctx);
338 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
339 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
340 log.info("saveConfigBlock Successful ");
341 } catch (Exception e) {
342 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
343 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
344 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
345 log.error("Failed in saveConfigBlock " + e.getMessage());
347 throw new SvcLogicException(e.getMessage());
351 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
353 log.info("Received saveTemplateConfig call with params : " + inParams);
355 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
359 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
360 DGGeneralDBService db = DGGeneralDBService.initialise();
362 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
364 ctx.setAttribute("tmp.convertconfig.escapeData",
365 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
366 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
367 ctx.getAttribute("config-template.file-content"));
370 saveConfigurationData(inParams, ctx);
372 ctx.setAttribute("tmp.convertconfig.escapeData",
373 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
374 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
375 ctx.getAttribute("tmp.merge.mergedData"));
379 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
380 ctx.getAttribute("config-template.config-file-id"), "Y");
381 if (status == QueryStatus.FAILURE)
382 throw new Exception("Unable to save prepare_relationship");
384 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
385 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
386 log.info("saveTemplateConfig Successful ");
387 } catch (Exception e) {
388 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
389 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
390 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
391 log.error("Failed in saveTemplateConfig " + e.getMessage());
393 throw new SvcLogicException(e.getMessage());
399 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
402 log.info("Received saveStyleSheet call with params : " + inParams);
404 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
408 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
409 ctx.setAttribute("tmp.convertconfig.escapeData",
410 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
411 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
412 ctx.getAttribute("tmp.merge.mergedData"));
415 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
416 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
417 log.info("saveStyleSheet Successful ");
418 } catch (Exception e) {
419 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
420 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
421 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
422 log.error("Failed in saveStyleSheet " + e.getMessage());
424 throw new SvcLogicException(e.getMessage());
429 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
432 log.info("Received saveStyleSheet call with params : " + inParams);
434 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
435 String siteLocation = ctx.getAttribute("site-location");
437 QueryStatus status = null;
442 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
443 DGGeneralDBService db = DGGeneralDBService.initialise();
447 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
449 if (status == QueryStatus.FAILURE)
450 throw new Exception("Unable to Read smm file");
453 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
455 if (status == QueryStatus.FAILURE)
456 throw new Exception("Unable to Read intermediate_ca_chain file");
460 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
463 if (status == QueryStatus.FAILURE)
464 throw new Exception("Unable to Read server_certificate_and_key file");
467 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
468 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
469 log.info("saveStyleSheet Successful ");
470 } catch (Exception e) {
471 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
472 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
473 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
474 log.error("Failed in saveStyleSheet " + e.getMessage());
476 throw new SvcLogicException(e.getMessage());
481 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
482 String fileContent, String deviceConfig) throws SvcLogicException {
483 ctx.setAttribute("data-source", dataSource);
484 ctx.setAttribute("file-content", fileContent);
485 ctx.setAttribute("file-category", "device_configuration");
486 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
488 saveConfigFiles(inParams, ctx);
491 public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
492 ctx.setAttribute("data-source", "Request");
493 ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
494 ctx.setAttribute("file-category", "configuration_block");
495 saveConfigFiles(inParams, ctx);
498 public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
499 ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
500 ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
501 ctx.setAttribute("file-category", "config_data");
502 saveConfigFiles(inParams, ctx);
506 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
507 throws SvcLogicException {
509 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
511 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
512 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
513 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
514 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
518 DGGeneralDBService db = DGGeneralDBService.initialise();
520 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
522 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
523 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
526 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
527 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
528 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
529 log.info("getConfigFilesByVnfVmNCategory Successful "
530 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
531 } catch (Exception e) {
532 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
533 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
534 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
535 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
537 throw new SvcLogicException(e.getMessage());
542 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
543 throws SvcLogicException {
545 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
547 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
549 DGGeneralDBService db = DGGeneralDBService.initialise();
551 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
553 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
554 throw new Exception("Unable to get download config template.");
557 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
558 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
559 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
560 log.info("getDownloadConfigTemplateByVnf Successful "
561 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
562 } catch (Exception e) {
563 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
564 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
565 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
566 log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
568 throw new SvcLogicException(e.getMessage());
573 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
577 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
579 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
580 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
584 SvcLogicContext logctx = new SvcLogicContext();
586 String escapedMessage = EscapeUtils.escapeSql(message);
589 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
590 logctx.setAttribute("log-message-type", messageType);
591 logctx.setAttribute("log-message", escapedMessage);
594 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
595 DGGeneralDBService db = DGGeneralDBService.initialise();
596 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
598 logctx.setAttribute("log-message", null);
600 if (status == QueryStatus.FAILURE)
601 throw new Exception("Unable to insert into config_transaction_log");
604 } catch (Exception e) {
605 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
606 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
607 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
610 throw new SvcLogicException(e.getMessage());
616 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
618 log.info("Received getVnfcReference call with params : " + inParams);
620 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
623 QueryStatus status = null;
628 DGGeneralDBService db = DGGeneralDBService.initialise();
630 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
631 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
633 if (status == QueryStatus.FAILURE)
634 throw new Exception("Unable to Read vnfc-reference");
636 // else if (status == QueryStatus.NOT_FOUND ) {
637 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
639 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
640 throw new Exception("Unable to Read vnfc reference");
644 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
645 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
646 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
647 log.info("getVnfcReference Successful ");
648 } catch (Exception e) {
649 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
650 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
651 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
652 log.error("Failed in getVnfcReference " + e.getMessage());
654 throw new SvcLogicException(e.getMessage());
658 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
659 log.info("Received getCapability call with params : " + inParams);
660 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
661 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
662 String caplevel = inParams.get("caplevel");
663 String findCapability = inParams.get("checkCapability");
664 String vServerId = inParams.get("vServerId");
665 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
666 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
667 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
668 log.info("getCapability Successful - No need for capability check for this action");
672 DGGeneralDBService db = DGGeneralDBService.initialise();
673 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
674 log.info("getCapability::returned from DB::+cap");
675 if (StringUtils.isBlank(cap)) {
676 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
677 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
678 log.info("getCapability Successful - No capability blocks found");
681 ObjectMapper mapper = new ObjectMapper();
682 JsonNode caps = mapper.readTree(cap);
683 log.info("From DB = " + caps);
684 JsonNode capabilities = caps.get("capabilities");
685 log.info("capabilities = " + capabilities);
686 if (caplevel != null && !caplevel.isEmpty()) {
687 JsonNode subCapabilities = capabilities.get(caplevel);
688 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
689 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
690 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
691 ctx.setAttribute("capabilities", "None");
692 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
693 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
694 log.info("getCapability Successful ");
697 if (findCapability != null && !findCapability.isEmpty()) {
698 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
699 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL))
700 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
702 ctx.setAttribute("capabilities", "Supported");
704 ctx.setAttribute("capabilities", "Not-Supported");
707 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
711 ctx.setAttribute(responsePrefix + "capabilities", capabilities.toString());
712 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
713 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
714 log.info("getCapability Successful ");
715 } catch (Exception e) {
716 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
717 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
718 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
719 log.error("Failed in getCapability " + e.getMessage());
721 throw new SvcLogicException(e.getMessage());
725 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
726 JsonNode subCapabilities) throws Exception {
727 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
729 if (subCapabilities.size() == 0) {
730 ctx.setAttribute("capabilities", "None");
731 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
734 JsonNode vmCaps = null;
735 for (JsonNode cap : subCapabilities) {
736 if (null != cap && null != cap.get(findCapability)
737 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
738 vmCaps = cap.get(findCapability);
739 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
744 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
745 ctx.setAttribute("capabilities", "Not-Supported");
746 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
750 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
751 if (StringUtils.isBlank(vnfcFunctionCode)) {
752 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
753 ctx.setAttribute("capabilities", "Not-Supported");
757 if (vmCaps.toString().contains(vnfcFunctionCode))
758 ctx.setAttribute("capabilities", "Supported");
760 ctx.setAttribute("capabilities", "Not-Supported");
761 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute("capabilities"));
764 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) throws Exception {
765 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
766 for (Object key : ctx.getAttributeKeySet()) {
767 String parmName = (String) key;
768 String parmValue = ctx.getAttribute(parmName);
769 log.info(parmName + "=" + parmValue);
772 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
773 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
774 return vnfcFunctionCode;
777 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
778 boolean capabilityCheckNeeded = true;
779 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
780 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<AppcDataServiceConstant.ACTIONS>(
781 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
782 for (AppcDataServiceConstant.ACTIONS action : actionList) {
783 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
784 capabilityCheckNeeded = false;
789 return capabilityCheckNeeded;