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.openecomp.appc.data.services.node;
25 import org.apache.commons.lang3.StringUtils;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.databind.JsonNode;
29 import com.fasterxml.jackson.databind.ObjectMapper;
31 import org.openecomp.sdnc.sli.SvcLogicContext;
32 import org.openecomp.sdnc.sli.SvcLogicException;
33 import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
35 import org.openecomp.appc.data.services.AppcDataServiceConstant;
36 import org.openecomp.appc.data.services.db.DGGeneralDBService;
37 import org.openecomp.appc.data.services.utils.EscapeUtils;
39 import org.openecomp.sdnc.sli.SvcLogicResource.QueryStatus;
41 public class ConfigResourceNode implements SvcLogicJavaPlugin {
43 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
45 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
47 log.info("Received getConfigFiles call with params : " + inParams);
49 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
53 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
54 DGGeneralDBService db = DGGeneralDBService.initialise();
55 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig",
56 "device_configuration");
58 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
59 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
61 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success",
62 "configuration_success");
64 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
65 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
67 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure",
68 "configuration_error");
70 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
71 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
73 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log");
75 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
76 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
79 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
80 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
81 log.info("GetConfigFileReference Successful ");
82 } catch (Exception e) {
83 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
84 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
85 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
86 log.error("Failed in GetConfigFileReference " + e.getMessage());
88 throw new SvcLogicException(e.getMessage());
92 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
94 log.info("Received getDeviceInfo call with params : " + inParams);
96 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
100 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
101 DGGeneralDBService db = DGGeneralDBService.initialise();
102 QueryStatus status = db.getDeviceAuthenticationByVnfType(ctx, "device-authentication");
104 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
105 throw new Exception("Unable to Read device_authentication");
107 status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
109 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
110 throw new Exception("Unable to Read device_interface_protocol");
112 status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
113 if (status == QueryStatus.FAILURE)
114 throw new Exception("Unable to Read configure_action_dg");
116 if (status == QueryStatus.NOT_FOUND) {
117 status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");
119 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
120 throw new Exception("Unable to Read configure_action_dg");
127 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
128 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
129 log.info("getCommonConfigInfo Successful ");
130 } catch (Exception e) {
131 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
132 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
133 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
134 log.error("Failed in getCommonConfigInfo " + e.getMessage());
136 throw new SvcLogicException(e.getMessage());
141 // fileCategory Can be config_template, parameter_definitions, parameter_yang
142 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
144 log.info("Received getTemplate call with params : " + inParams);
147 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
148 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
149 String templateName = ctx.getAttribute("template-name");
150 QueryStatus status = null;
151 String responsePrefix1 = "";
155 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
156 log.info("RESPONSEPREFIX : " + responsePrefix);
157 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
159 DGGeneralDBService db = DGGeneralDBService.initialise();
161 if (StringUtils.isBlank(templateName)) {
163 //if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
166 status = db.getTemplate(ctx, responsePrefix, fileCategory);
167 if (status == QueryStatus.FAILURE)
168 throw new Exception("Unable to Read " + fileCategory );
171 if (status == QueryStatus.NOT_FOUND) {
174 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
176 if (status == QueryStatus.FAILURE)
177 throw new Exception("Unable to Read " + fileCategory );
179 if (status == QueryStatus.NOT_FOUND) {
181 status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
183 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
184 throw new Exception("Unable to Read " + fileCategory );
189 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
191 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
192 throw new Exception("Unable to Read " + fileCategory + " template");
196 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
197 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
198 log.info("GetTemplate Successful ");
199 } catch (Exception e) {
200 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
201 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
202 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
203 log.error("Failed in getTemplate " + e.getMessage());
205 throw new SvcLogicException(e.getMessage());
209 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
211 log.info("Received saveConfigFiles call with params : " + inParams);
213 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
217 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
218 DGGeneralDBService db = DGGeneralDBService.initialise();
219 QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
221 if (status == QueryStatus.FAILURE)
222 throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
224 status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
226 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
227 throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
229 status = db.savePrepareRelationship(ctx, "tmp.preparerel",
230 ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
231 if (status == QueryStatus.FAILURE)
232 throw new Exception("Unable to save prepare_relationship");
234 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
235 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
236 log.info("saveConfigFiles Successful ");
237 } catch (Exception e) {
238 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
239 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
240 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
241 log.error("Failed in saveConfigFiles " + e.getMessage());
243 throw new SvcLogicException(e.getMessage());
247 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
249 log.info("Received updateUploadConfig call with params : " + inParams);
251 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
255 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
256 DGGeneralDBService db = DGGeneralDBService.initialise();
258 ctx.setAttribute("tmp.escaped.devicerunningconfig",
259 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
261 QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
263 if (status == QueryStatus.FAILURE)
264 throw new Exception("Unable to Save configuration in upload_config");
266 /*status = db.getMaxUploadConfigFileId(ctx, "tmp.uploadconfigmax");
268 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
269 throw new Exception("Unable to get record from upload_config");
271 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
272 Integer.parseInt(ctx.getAttribute("tmp.uploadconfigmax.uploadconfigid")));
273 if (status == QueryStatus.FAILURE)
274 throw new Exception("Unable to upload upload_config");*/
276 status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
278 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
279 throw new Exception("Unable to get record from upload_config");
281 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
282 Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
283 if (status == QueryStatus.FAILURE)
284 throw new Exception("Unable to upload upload_config");
286 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
287 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
288 log.info("updateUploadConfig Successful ");
289 } catch (Exception e) {
290 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
291 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
292 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
293 log.error("Failed in updateUploadConfig " + e.getMessage());
295 throw new SvcLogicException(e.getMessage());
299 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
301 log.info("Received savePrepareRelationship call with params : " + inParams);
303 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
304 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
305 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
308 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
309 DGGeneralDBService db = DGGeneralDBService.initialise();
311 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
312 if (status == QueryStatus.FAILURE)
313 throw new Exception("Unable to save prepare_relationship");
315 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
316 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
317 log.info("savePrepareRelationship Successful ");
318 } catch (Exception e) {
319 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
320 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
321 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
322 log.error("Failed in saveConfigFiles " + e.getMessage());
324 throw new SvcLogicException(e.getMessage());
328 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
330 log.info("Received saveConfigBlock call with params : " + inParams);
332 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
336 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
337 ctx.setAttribute("tmp.convertconfig.escapeData",
338 EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
339 DGGeneralDBService db = DGGeneralDBService.initialise();
341 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
342 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
343 ctx.getAttribute("configuration"));
346 saveConfigurationBlock(inParams, ctx);
348 ctx.setAttribute("tmp.convertconfig.escapeData",
349 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
350 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
351 ctx.getAttribute("tmp.merge.mergedData"));
353 saveConfigurationData(inParams, ctx);
356 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
357 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
358 log.info("saveConfigBlock Successful ");
359 } catch (Exception e) {
360 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
361 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
362 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
363 log.error("Failed in saveConfigBlock " + e.getMessage());
365 throw new SvcLogicException(e.getMessage());
369 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
371 log.info("Received saveTemplateConfig call with params : " + inParams);
373 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
377 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
378 DGGeneralDBService db = DGGeneralDBService.initialise();
380 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
382 ctx.setAttribute("tmp.convertconfig.escapeData",
383 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
384 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
385 ctx.getAttribute("config-template.file-content"));
388 saveConfigurationData(inParams, ctx);
390 ctx.setAttribute("tmp.convertconfig.escapeData",
391 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
392 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
393 ctx.getAttribute("tmp.merge.mergedData"));
397 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
398 ctx.getAttribute("config-template.config-file-id"), "Y");
399 if (status == QueryStatus.FAILURE)
400 throw new Exception("Unable to save prepare_relationship");
402 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
403 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
404 log.info("saveTemplateConfig Successful ");
405 } catch (Exception e) {
406 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
407 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
408 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
409 log.error("Failed in saveTemplateConfig " + e.getMessage());
411 throw new SvcLogicException(e.getMessage());
418 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
421 log.info("Received saveStyleSheet call with params : " + inParams);
423 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
427 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
428 ctx.setAttribute("tmp.convertconfig.escapeData",
429 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
430 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
431 ctx.getAttribute("tmp.merge.mergedData"));
434 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
435 log.info("saveStyleSheet Successful ");
436 } catch (Exception e) {
437 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
438 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
439 log.error("Failed in saveStyleSheet " + e.getMessage());
441 throw new SvcLogicException(e.getMessage());
446 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
449 log.info("Received saveStyleSheet call with params : " + inParams);
451 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
452 String siteLocation = ctx.getAttribute("site-location");
454 QueryStatus status = null;
459 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
460 DGGeneralDBService db = DGGeneralDBService.initialise();
464 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
466 if ( status == QueryStatus.FAILURE )
467 throw new Exception("Unable to Read smm file");
470 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
472 if ( status == QueryStatus.FAILURE )
473 throw new Exception("Unable to Read intermediate_ca_chain file");
478 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key", siteLocation);
480 if ( status == QueryStatus.FAILURE )
481 throw new Exception("Unable to Read server_certificate_and_key file");
484 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
485 log.info("saveStyleSheet Successful ");
486 } catch (Exception e) {
487 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
488 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
489 log.error("Failed in saveStyleSheet " + e.getMessage());
491 throw new SvcLogicException(e.getMessage());
496 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
497 String fileContent, String deviceConfig) throws SvcLogicException {
498 ctx.setAttribute("data-source", dataSource);
499 ctx.setAttribute("file-content", fileContent);
500 ctx.setAttribute("file-category", "device_configuration");
501 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
503 saveConfigFiles(inParams, ctx);
506 public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
507 ctx.setAttribute("data-source", "Request");
508 ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
509 ctx.setAttribute("file-category", "configuration_block");
510 saveConfigFiles(inParams, ctx);
513 public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
514 ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
515 ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
516 ctx.setAttribute("file-category", "config_data");
517 saveConfigFiles(inParams, ctx);
521 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
523 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
525 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
526 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
527 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
528 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
532 DGGeneralDBService db = DGGeneralDBService.initialise();
534 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
536 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
537 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
540 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
541 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
542 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
543 log.info("getConfigFilesByVnfVmNCategory Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
544 } catch (Exception e) {
545 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
546 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
547 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
548 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
550 throw new SvcLogicException(e.getMessage());
555 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
557 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
559 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
561 DGGeneralDBService db = DGGeneralDBService.initialise();
563 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
565 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
566 throw new Exception("Unable to get download config template.");
569 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
570 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
571 log.info("getDownloadConfigTemplateByVnf Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
572 } catch (Exception e) {
573 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
574 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
575 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
576 log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
578 throw new SvcLogicException(e.getMessage());
583 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
587 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
589 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
590 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
594 SvcLogicContext logctx = new SvcLogicContext();
596 String escapedMessage = EscapeUtils.escapeSql(message);
599 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
600 logctx.setAttribute("log-message-type", messageType);
601 logctx.setAttribute("log-message", escapedMessage);
604 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
605 DGGeneralDBService db = DGGeneralDBService.initialise();
606 QueryStatus status = db.saveConfigTransactionLog( logctx, responsePrefix);
608 logctx.setAttribute("log-message", null);
610 if (status == QueryStatus.FAILURE)
611 throw new Exception("Unable to insert into config_transaction_log");
614 } catch (Exception e) {
615 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
616 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
617 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
620 throw new SvcLogicException(e.getMessage());
626 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
628 log.info("Received getVnfcReference call with params : " + inParams);
630 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
633 QueryStatus status = null;
638 DGGeneralDBService db = DGGeneralDBService.initialise();
640 if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
641 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
643 if ( status == QueryStatus.FAILURE)
644 throw new Exception("Unable to Read vnfc-reference");
646 //else if (status == QueryStatus.NOT_FOUND ) {
647 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
649 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
650 throw new Exception("Unable to Read vnfc reference");
654 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
655 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
656 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
657 log.info("getVnfcReference Successful ");
658 } catch (Exception e) {
659 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
660 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
661 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
662 log.error("Failed in getVnfcReference " + e.getMessage());
664 throw new SvcLogicException(e.getMessage());
668 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
669 log.info("Received getCapability call with params : " + inParams);
670 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
671 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
672 String caplevel = inParams.get("caplevel");
673 String findCapability = inParams.get("checkCapability");
676 DGGeneralDBService db = DGGeneralDBService.initialise();
677 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
678 ObjectMapper mapper = new ObjectMapper();
679 JsonNode caps = mapper.readTree(cap);
680 log.info("From DB = " + caps);
681 JsonNode capabilities = caps.get("capabilities");
682 log.info("capabilities = " + capabilities);
683 if(caplevel !=null && !caplevel.isEmpty()){
684 JsonNode subCapabilities = capabilities.get(caplevel);
685 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
686 if(findCapability !=null && !findCapability.isEmpty()){
687 if(subCapabilities != null && subCapabilities.toString().contains(findCapability))
688 ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." + findCapability,
691 ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." + findCapability,
696 ctx.setAttribute(responsePrefix + "capabilities." + caplevel,
697 subCapabilities.toString());
702 ctx.setAttribute(responsePrefix + "capabilities",
703 capabilities.toString());
704 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
705 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
706 log.info("getCapability Successful ");
707 } catch (Exception e) {
708 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
709 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
710 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
711 log.error("Failed in getCapability " + e.getMessage());
713 throw new SvcLogicException(e.getMessage());
718 /*public void getUploadConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
720 log.info("Received getUploadConfigInfo call with params : " + inParams);
722 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
724 String uploadConfigId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_UPLOAD_CONFIG_ID);
725 QueryStatus status = null;
731 DGGeneralDBService db = DGGeneralDBService.initialise();
733 if ( uploadConfigId != null )
734 id = Integer.parseInt(uploadConfigId);
736 status = db.getUploadConfigInfo(ctx, responsePrefix,id);
738 if ( status == QueryStatus.FAILURE || status == QueryStatus.NOT_FOUND)
739 throw new Exception("Unable to Read upload-config");
742 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
743 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
744 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
745 log.info("getUploadConfigInfo Successful ");
746 } catch (Exception e) {
747 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
748 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
749 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
750 log.error("Failed in getUploadConfigInfo " + e.getMessage());
752 throw new SvcLogicException(e.getMessage());