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;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
28 import org.apache.commons.lang3.StringUtils;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
38 import org.onap.appc.data.services.AppcDataServiceConstant;
39 import org.onap.appc.data.services.db.DGGeneralDBService;
40 import org.onap.appc.data.services.utils.EscapeUtils;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
44 public class ConfigResourceNode implements SvcLogicJavaPlugin {
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
48 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
50 log.info("Received getConfigFiles call with params : " + inParams);
52 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
56 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
57 DGGeneralDBService db = DGGeneralDBService.initialise();
58 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig",
59 "device_configuration");
61 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
62 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
64 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success",
65 "configuration_success");
67 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
68 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
70 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure",
71 "configuration_error");
73 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
74 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
76 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log");
78 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
79 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
82 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
83 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
84 log.info("GetConfigFileReference Successful ");
85 } catch (Exception e) {
86 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
87 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
88 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
89 log.error("Failed in GetConfigFileReference " + e.getMessage());
91 throw new SvcLogicException(e.getMessage());
95 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
97 log.info("Received getDeviceInfo call with params : " + inParams);
99 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
103 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
104 DGGeneralDBService db = DGGeneralDBService.initialise();
105 QueryStatus status = db.getDeviceAuthenticationByVnfType(ctx, "device-authentication");
107 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
108 throw new Exception("Unable to Read device_authentication");
110 status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
112 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
113 throw new Exception("Unable to Read device_interface_protocol");
115 status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
116 if (status == QueryStatus.FAILURE)
117 throw new Exception("Unable to Read configure_action_dg");
119 if (status == QueryStatus.NOT_FOUND) {
120 status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");
122 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
123 throw new Exception("Unable to Read configure_action_dg");
130 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
131 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
132 log.info("getCommonConfigInfo Successful ");
133 } catch (Exception e) {
134 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
135 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
136 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
137 log.error("Failed in getCommonConfigInfo " + e.getMessage());
139 throw new SvcLogicException(e.getMessage());
144 // fileCategory Can be config_template, parameter_definitions, parameter_yang
145 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
147 log.info("Received getTemplate call with params : " + inParams);
150 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
151 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
152 String templateName = ctx.getAttribute("template-name");
153 QueryStatus status = null;
154 String responsePrefix1 = "";
158 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
159 log.info("RESPONSEPREFIX : " + responsePrefix);
160 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
162 DGGeneralDBService db = DGGeneralDBService.initialise();
164 if (StringUtils.isBlank(templateName)) {
166 //if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
169 status = db.getTemplate(ctx, responsePrefix, fileCategory);
170 if (status == QueryStatus.FAILURE)
171 throw new Exception("Unable to Read " + fileCategory );
174 if (status == QueryStatus.NOT_FOUND) {
177 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
179 if (status == QueryStatus.FAILURE)
180 throw new Exception("Unable to Read " + fileCategory );
182 if (status == QueryStatus.NOT_FOUND) {
184 //status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
186 //if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
187 throw new Exception("Unable to Read " + fileCategory );
192 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
194 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
195 throw new Exception("Unable to Read " + fileCategory + " template");
199 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
200 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
201 log.info("GetTemplate Successful ");
202 } catch (Exception e) {
203 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
204 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
205 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
206 log.error("Failed in getTemplate " + e.getMessage());
208 throw new SvcLogicException(e.getMessage());
212 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
214 log.info("Received saveConfigFiles call with params : " + inParams);
216 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
220 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
221 DGGeneralDBService db = DGGeneralDBService.initialise();
222 QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
224 if (status == QueryStatus.FAILURE)
225 throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
227 status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
229 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
230 throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
232 status = db.savePrepareRelationship(ctx, "tmp.preparerel",
233 ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
234 if (status == QueryStatus.FAILURE)
235 throw new Exception("Unable to save prepare_relationship");
237 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
238 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
239 log.info("saveConfigFiles Successful ");
240 } catch (Exception e) {
241 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
242 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
243 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
244 log.error("Failed in saveConfigFiles " + e.getMessage());
246 throw new SvcLogicException(e.getMessage());
250 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
252 log.info("Received updateUploadConfig call with params : " + inParams);
254 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
258 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
259 DGGeneralDBService db = DGGeneralDBService.initialise();
261 ctx.setAttribute("tmp.escaped.devicerunningconfig",
262 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
264 QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
266 if (status == QueryStatus.FAILURE)
267 throw new Exception("Unable to Save configuration in upload_config");
269 /*status = db.getMaxUploadConfigFileId(ctx, "tmp.uploadconfigmax");
271 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
272 throw new Exception("Unable to get record from upload_config");
274 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
275 Integer.parseInt(ctx.getAttribute("tmp.uploadconfigmax.uploadconfigid")));
276 if (status == QueryStatus.FAILURE)
277 throw new Exception("Unable to upload upload_config");*/
279 status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
281 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
282 throw new Exception("Unable to get record from upload_config");
284 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
285 Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
286 if (status == QueryStatus.FAILURE)
287 throw new Exception("Unable to upload upload_config");
289 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
290 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
291 log.info("updateUploadConfig Successful ");
292 } catch (Exception e) {
293 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
294 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
295 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
296 log.error("Failed in updateUploadConfig " + e.getMessage());
298 throw new SvcLogicException(e.getMessage());
302 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
304 log.info("Received savePrepareRelationship call with params : " + inParams);
306 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
307 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
308 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
311 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
312 DGGeneralDBService db = DGGeneralDBService.initialise();
314 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
315 if (status == QueryStatus.FAILURE)
316 throw new Exception("Unable to save prepare_relationship");
318 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
319 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
320 log.info("savePrepareRelationship Successful ");
321 } catch (Exception e) {
322 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
323 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
324 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
325 log.error("Failed in saveConfigFiles " + e.getMessage());
327 throw new SvcLogicException(e.getMessage());
331 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
333 log.info("Received saveConfigBlock call with params : " + inParams);
335 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
339 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
340 ctx.setAttribute("tmp.convertconfig.escapeData",
341 EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
342 DGGeneralDBService db = DGGeneralDBService.initialise();
344 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
345 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
346 ctx.getAttribute("configuration"));
349 saveConfigurationBlock(inParams, ctx);
351 ctx.setAttribute("tmp.convertconfig.escapeData",
352 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
353 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
354 ctx.getAttribute("tmp.merge.mergedData"));
356 saveConfigurationData(inParams, ctx);
359 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
360 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
361 log.info("saveConfigBlock Successful ");
362 } catch (Exception e) {
363 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
364 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
365 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
366 log.error("Failed in saveConfigBlock " + e.getMessage());
368 throw new SvcLogicException(e.getMessage());
372 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
374 log.info("Received saveTemplateConfig call with params : " + inParams);
376 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
380 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
381 DGGeneralDBService db = DGGeneralDBService.initialise();
383 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
385 ctx.setAttribute("tmp.convertconfig.escapeData",
386 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
387 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
388 ctx.getAttribute("config-template.file-content"));
391 saveConfigurationData(inParams, ctx);
393 ctx.setAttribute("tmp.convertconfig.escapeData",
394 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
395 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
396 ctx.getAttribute("tmp.merge.mergedData"));
400 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
401 ctx.getAttribute("config-template.config-file-id"), "Y");
402 if (status == QueryStatus.FAILURE)
403 throw new Exception("Unable to save prepare_relationship");
405 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
406 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
407 log.info("saveTemplateConfig Successful ");
408 } catch (Exception e) {
409 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
410 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
411 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
412 log.error("Failed in saveTemplateConfig " + e.getMessage());
414 throw new SvcLogicException(e.getMessage());
421 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
424 log.info("Received saveStyleSheet call with params : " + inParams);
426 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
430 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
431 ctx.setAttribute("tmp.convertconfig.escapeData",
432 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
433 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
434 ctx.getAttribute("tmp.merge.mergedData"));
437 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
438 log.info("saveStyleSheet Successful ");
439 } catch (Exception e) {
440 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
441 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
442 log.error("Failed in saveStyleSheet " + e.getMessage());
444 throw new SvcLogicException(e.getMessage());
449 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
452 log.info("Received saveStyleSheet call with params : " + inParams);
454 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
455 String siteLocation = ctx.getAttribute("site-location");
457 QueryStatus status = null;
462 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
463 DGGeneralDBService db = DGGeneralDBService.initialise();
467 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
469 if ( status == QueryStatus.FAILURE )
470 throw new Exception("Unable to Read smm file");
473 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
475 if ( status == QueryStatus.FAILURE )
476 throw new Exception("Unable to Read intermediate_ca_chain file");
481 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key", siteLocation);
483 if ( status == QueryStatus.FAILURE )
484 throw new Exception("Unable to Read server_certificate_and_key file");
487 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
488 log.info("saveStyleSheet Successful ");
489 } catch (Exception e) {
490 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
491 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
492 log.error("Failed in saveStyleSheet " + e.getMessage());
494 throw new SvcLogicException(e.getMessage());
499 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
500 String fileContent, String deviceConfig) throws SvcLogicException {
501 ctx.setAttribute("data-source", dataSource);
502 ctx.setAttribute("file-content", fileContent);
503 ctx.setAttribute("file-category", "device_configuration");
504 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
506 saveConfigFiles(inParams, ctx);
509 public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
510 ctx.setAttribute("data-source", "Request");
511 ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
512 ctx.setAttribute("file-category", "configuration_block");
513 saveConfigFiles(inParams, ctx);
516 public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
517 ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
518 ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
519 ctx.setAttribute("file-category", "config_data");
520 saveConfigFiles(inParams, ctx);
524 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
526 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
528 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
529 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
530 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
531 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
535 DGGeneralDBService db = DGGeneralDBService.initialise();
537 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
539 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
540 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
543 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
544 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
545 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
546 log.info("getConfigFilesByVnfVmNCategory Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
547 } catch (Exception e) {
548 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
549 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
550 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
551 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
553 throw new SvcLogicException(e.getMessage());
558 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
560 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
562 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
564 DGGeneralDBService db = DGGeneralDBService.initialise();
566 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
568 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
569 throw new Exception("Unable to get download config template.");
572 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
573 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
574 log.info("getDownloadConfigTemplateByVnf Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
575 } catch (Exception e) {
576 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
577 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
578 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
579 log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
581 throw new SvcLogicException(e.getMessage());
586 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
590 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
592 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
593 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
597 SvcLogicContext logctx = new SvcLogicContext();
599 String escapedMessage = EscapeUtils.escapeSql(message);
602 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
603 logctx.setAttribute("log-message-type", messageType);
604 logctx.setAttribute("log-message", escapedMessage);
607 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
608 DGGeneralDBService db = DGGeneralDBService.initialise();
609 QueryStatus status = db.saveConfigTransactionLog( logctx, responsePrefix);
611 logctx.setAttribute("log-message", null);
613 if (status == QueryStatus.FAILURE)
614 throw new Exception("Unable to insert into config_transaction_log");
617 } catch (Exception e) {
618 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
619 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
620 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
623 throw new SvcLogicException(e.getMessage());
629 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
631 log.info("Received getVnfcReference call with params : " + inParams);
633 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
636 QueryStatus status = null;
641 DGGeneralDBService db = DGGeneralDBService.initialise();
643 if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
644 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
646 if ( status == QueryStatus.FAILURE)
647 throw new Exception("Unable to Read vnfc-reference");
649 //else if (status == QueryStatus.NOT_FOUND ) {
650 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
652 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
653 throw new Exception("Unable to Read vnfc reference");
657 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
658 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
659 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
660 log.info("getVnfcReference Successful ");
661 } catch (Exception e) {
662 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
663 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
664 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
665 log.error("Failed in getVnfcReference " + e.getMessage());
667 throw new SvcLogicException(e.getMessage());
671 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
672 log.info("Received getCapability call with params : " + inParams);
673 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
674 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
675 String caplevel = inParams.get("caplevel");
676 String findCapability = inParams.get("checkCapability");
678 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability))
680 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
681 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
682 log.info("getCapability Successful - No need for capability check for this action");
686 DGGeneralDBService db = DGGeneralDBService.initialise();
687 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
688 log.info("getCapability::returned from DB::+cap");
689 if (StringUtils.isBlank(cap)) {
690 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
691 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
692 log.info("getCapability Successful - No capability blocks found");
696 ObjectMapper mapper = new ObjectMapper();
697 JsonNode caps = mapper.readTree(cap);
698 log.info("From DB = " + caps);
699 JsonNode capabilities = caps.get("capabilities");
700 log.info("capabilities = " + capabilities);
701 if(caplevel !=null && !caplevel.isEmpty()){
702 JsonNode subCapabilities = capabilities.get(caplevel);
703 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
704 if(findCapability !=null && !findCapability.isEmpty()){
705 if(subCapabilities != null && subCapabilities.toString().contains(findCapability))
706 ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." + findCapability,
709 ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." + findCapability,
714 ctx.setAttribute(responsePrefix + "capabilities." + caplevel,
715 subCapabilities.toString());
720 ctx.setAttribute(responsePrefix + "capabilities",
721 capabilities.toString());
722 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
723 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
724 log.info("getCapability Successful ");
725 } catch (Exception e) {
726 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
727 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
728 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
729 log.error("Failed in getCapability " + e.getMessage());
731 throw new SvcLogicException(e.getMessage());
735 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
736 boolean capabilityCheckNeeded = true;
737 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
738 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<AppcDataServiceConstant.ACTIONS>(
739 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
740 for (AppcDataServiceConstant.ACTIONS action : actionList) {
741 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
742 capabilityCheckNeeded = false;
747 return capabilityCheckNeeded;