2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.data.services.node;
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;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.List;
34 import org.apache.commons.lang3.StringUtils;
35 import org.onap.appc.data.services.AppcDataServiceConstant;
36 import org.onap.appc.data.services.db.DGGeneralDBService;
37 import org.onap.appc.data.services.utils.EscapeUtils;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
43 public class ConfigResourceNode implements SvcLogicJavaPlugin {
45 static final String DEVICE_CONF_PREFIX = "configfilereference-deviceconfig";
46 static final String DEVICE_CONF_FILE_TYPE = "device_configuration";
48 static final String SUCCESS_PREFIX = "configfilereference-success";
49 static final String SUCCESS_FILE_TYPE = "configuration_success";
51 static final String FAILURE_PREFIX = "configfilereference-failure";
52 static final String FAILURE_FILE_TYPE = "configuration_error";
54 static final String LOG_PREFIX = "configfilereference-log";
55 static final String LOG_FILE_TYPE = "log";
57 static final String DEVICE_PROTOCOL_PREFIX = "tmp.deviceinterfaceprotocol";
58 static final String CONF_ACTION_PREFIX = "tmp.configureactiondg";
60 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
61 private final DGGeneralDBService db;
64 * Constructor which provide default DB service
66 public ConfigResourceNode() {
67 db = DGGeneralDBService.initialise();
71 * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
73 public ConfigResourceNode(DGGeneralDBService dbService) {
77 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
79 log.info("Received getConfigFiles call with params : " + inParams);
80 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
83 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
84 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
86 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
87 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
89 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
91 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
92 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
94 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
96 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
97 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
99 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
101 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
102 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
104 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
105 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
106 log.info("GetConfigFileReference Successful ");
107 } catch (Exception e) {
108 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
109 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
110 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
111 log.error("Failed in GetConfigFileReference " + e.getMessage());
113 throw new SvcLogicException(e.getMessage());
117 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
119 log.info("Received getDeviceInfo call with params : " + inParams);
120 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
123 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
124 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, DEVICE_PROTOCOL_PREFIX);
126 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
127 throw new Exception("Unable to Read device_interface_protocol");
129 status = db.getConfigureActionDGByVnfTypeNAction(ctx, CONF_ACTION_PREFIX);
130 if (status == QueryStatus.FAILURE)
131 throw new Exception("Unable to Read configure_action_dg");
133 if (status == QueryStatus.NOT_FOUND) {
134 status = db.getConfigureActionDGByVnfType(ctx, CONF_ACTION_PREFIX);
136 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
137 throw new Exception("Unable to Read configure_action_dg");
140 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
141 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
142 log.info("getCommonConfigInfo Successful ");
143 } catch (Exception e) {
144 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
145 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
146 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
147 log.error("Failed in getCommonConfigInfo " + e.getMessage());
149 throw new SvcLogicException(e.getMessage());
154 * FileCategory can be config_template, parameter_definitions, parameter_yang
156 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
158 log.info("Received getTemplate call with params : " + inParams);
160 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
161 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
162 String templateName = ctx.getAttribute("template-name");
163 QueryStatus status = null;
164 String responsePrefix1 = "";
168 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
169 log.info("RESPONSEPREFIX : " + responsePrefix);
170 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
172 if (StringUtils.isBlank(templateName)) {
174 // if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
176 status = db.getTemplate(ctx, responsePrefix, fileCategory);
177 if (status == QueryStatus.FAILURE)
178 throw new Exception("Unable to Read " + fileCategory);
181 if (status == QueryStatus.NOT_FOUND) {
184 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
186 if (status == QueryStatus.FAILURE)
187 throw new Exception("Unable to Read " + fileCategory);
189 if (status == QueryStatus.NOT_FOUND) {
191 // status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
193 // if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
194 throw new Exception("Unable to Read " + fileCategory);
199 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
201 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
202 throw new Exception("Unable to Read " + fileCategory + " template");
205 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
206 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
207 log.info("GetTemplate Successful ");
208 } catch (Exception e) {
209 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
210 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
211 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
212 log.error("Failed in getTemplate " + e.getMessage());
214 throw new SvcLogicException(e.getMessage());
218 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
220 log.info("Received saveConfigFiles call with params : " + inParams);
222 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
226 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
227 QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
229 if (status == QueryStatus.FAILURE)
230 throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
232 status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
234 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
235 throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
237 status = db.savePrepareRelationship(ctx, "tmp.preparerel",
238 ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
239 if (status == QueryStatus.FAILURE)
240 throw new Exception("Unable to save prepare_relationship");
242 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
243 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
244 log.info("saveConfigFiles Successful ");
245 } catch (Exception e) {
246 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
247 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
248 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
249 log.error("Failed in saveConfigFiles " + e.getMessage());
251 throw new SvcLogicException(e.getMessage());
255 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
257 log.info("Received updateUploadConfig call with params : " + inParams);
259 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
263 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
265 ctx.setAttribute("tmp.escaped.devicerunningconfig",
266 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
268 QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
270 if (status == QueryStatus.FAILURE)
271 throw new Exception("Unable to Save configuration in upload_config");
273 status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
275 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
276 throw new Exception("Unable to get record from upload_config");
278 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
279 Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
280 if (status == QueryStatus.FAILURE)
281 throw new Exception("Unable to upload upload_config");
283 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
284 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
285 log.info("updateUploadConfig Successful ");
286 } catch (Exception e) {
287 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
288 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
289 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
290 log.error("Failed in updateUploadConfig " + e.getMessage());
292 throw new SvcLogicException(e.getMessage());
296 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
298 log.info("Received savePrepareRelationship call with params : " + inParams);
300 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
301 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
302 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
305 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
307 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
308 if (status == QueryStatus.FAILURE)
309 throw new Exception("Unable to save prepare_relationship");
311 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
312 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
313 log.info("savePrepareRelationship Successful ");
314 } catch (Exception e) {
315 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
316 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
317 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
318 log.error("Failed in saveConfigFiles " + e.getMessage());
320 throw new SvcLogicException(e.getMessage());
324 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
326 log.info("Received saveConfigBlock call with params : " + inParams);
328 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
331 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
332 ctx.setAttribute("tmp.convertconfig.escapeData", EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
334 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
335 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
336 ctx.getAttribute("configuration"));
339 saveConfigurationBlock(inParams, ctx);
341 ctx.setAttribute("tmp.convertconfig.escapeData",
342 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
343 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
344 ctx.getAttribute("tmp.merge.mergedData"));
346 saveConfigurationData(inParams, ctx);
349 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
350 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
351 log.info("saveConfigBlock Successful ");
352 } catch (Exception e) {
353 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
354 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
355 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
356 log.error("Failed in saveConfigBlock " + e.getMessage());
358 throw new SvcLogicException(e.getMessage());
362 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
364 log.info("Received saveTemplateConfig call with params : " + inParams);
366 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
369 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
371 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
373 ctx.setAttribute("tmp.convertconfig.escapeData",
374 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
375 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
376 ctx.getAttribute("config-template.file-content"));
379 saveConfigurationData(inParams, ctx);
381 ctx.setAttribute("tmp.convertconfig.escapeData",
382 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
383 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
384 ctx.getAttribute("tmp.merge.mergedData"));
388 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
389 ctx.getAttribute("config-template.config-file-id"), "Y");
390 if (status == QueryStatus.FAILURE)
391 throw new Exception("Unable to save prepare_relationship");
393 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
394 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
395 log.info("saveTemplateConfig Successful ");
396 } catch (Exception e) {
397 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
398 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
399 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
400 log.error("Failed in saveTemplateConfig " + e.getMessage());
402 throw new SvcLogicException(e.getMessage());
406 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
408 log.info("Received saveStyleSheet call with params : " + inParams);
410 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
414 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
415 ctx.setAttribute("tmp.convertconfig.escapeData",
416 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
417 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
418 ctx.getAttribute("tmp.merge.mergedData"));
420 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
421 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
422 log.info("saveStyleSheet Successful ");
423 } catch (Exception e) {
424 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
425 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
426 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
427 log.error("Failed in saveStyleSheet " + e.getMessage());
429 throw new SvcLogicException(e.getMessage());
433 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
435 log.info("Received saveStyleSheet call with params : " + inParams);
437 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
438 String siteLocation = ctx.getAttribute("site-location");
440 QueryStatus status = null;
444 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
446 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
448 if (status == QueryStatus.FAILURE)
449 throw new Exception("Unable to Read smm file");
451 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
453 if (status == QueryStatus.FAILURE)
454 throw new Exception("Unable to Read intermediate_ca_chain file");
456 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
459 if (status == QueryStatus.FAILURE)
460 throw new Exception("Unable to Read server_certificate_and_key file");
462 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
463 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
464 log.info("saveStyleSheet Successful ");
465 } catch (Exception e) {
466 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
467 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
468 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
469 log.error("Failed in saveStyleSheet " + e.getMessage());
471 throw new SvcLogicException(e.getMessage());
475 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
476 String fileContent, String deviceConfig) throws SvcLogicException {
477 ctx.setAttribute("data-source", dataSource);
478 ctx.setAttribute("file-content", fileContent);
479 ctx.setAttribute("file-category", "device_configuration");
480 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
482 saveConfigFiles(inParams, ctx);
485 public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
486 ctx.setAttribute("data-source", "Request");
487 ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
488 ctx.setAttribute("file-category", "configuration_block");
489 saveConfigFiles(inParams, ctx);
492 public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
493 ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
494 ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
495 ctx.setAttribute("file-category", "config_data");
496 saveConfigFiles(inParams, ctx);
499 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
500 throws SvcLogicException {
502 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
504 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
505 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
506 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
507 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
509 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
511 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
512 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
514 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
515 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
516 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
517 log.info("getConfigFilesByVnfVmNCategory Successful "
518 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
519 } catch (Exception e) {
520 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
521 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
522 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
523 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
525 throw new SvcLogicException(e.getMessage());
529 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
530 throws SvcLogicException {
532 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
534 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
536 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
538 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
539 throw new Exception("Unable to get download config template.");
541 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
542 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
543 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
544 log.info("getDownloadConfigTemplateByVnf Successful "
545 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
546 } catch (Exception e) {
547 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
548 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
549 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
550 log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
552 throw new SvcLogicException(e.getMessage());
556 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
558 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
560 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
561 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
565 SvcLogicContext logctx = new SvcLogicContext();
566 String escapedMessage = EscapeUtils.escapeSql(message);
568 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
569 logctx.setAttribute("log-message-type", messageType);
570 logctx.setAttribute("log-message", escapedMessage);
572 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
573 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
575 logctx.setAttribute("log-message", null);
577 if (status == QueryStatus.FAILURE)
578 throw new Exception("Unable to insert into config_transaction_log");
580 } catch (Exception e) {
581 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
582 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
583 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
585 throw new SvcLogicException(e.getMessage());
589 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
591 log.info("Received getVnfcReference call with params : " + inParams);
593 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
594 QueryStatus status = null;
597 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
598 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
600 if (status == QueryStatus.FAILURE)
601 throw new Exception("Unable to Read vnfc-reference");
603 // else if (status == QueryStatus.NOT_FOUND ) {
604 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
606 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
607 throw new Exception("Unable to Read vnfc reference");
611 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
612 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
613 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
614 log.info("getVnfcReference Successful ");
615 } catch (Exception e) {
616 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
617 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
618 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
619 log.error("Failed in getVnfcReference " + e.getMessage());
621 throw new SvcLogicException(e.getMessage());
625 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
626 log.info("Received getCapability call with params : " + inParams);
627 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
628 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
629 String caplevel = inParams.get("caplevel");
630 String findCapability = inParams.get("checkCapability");
631 String vServerId = inParams.get("vServerId");
632 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
633 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
634 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
635 log.info("getCapability Successful - No need for capability check for this action");
639 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
640 log.info("getCapability::returned from DB::+cap");
641 if (StringUtils.isBlank(cap)) {
642 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
643 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
644 log.info("getCapability Successful - No capability blocks found");
647 ObjectMapper mapper = new ObjectMapper();
648 JsonNode caps = mapper.readTree(cap);
649 log.info("From DB = " + caps);
650 JsonNode capabilities = caps.get("capabilities");
651 log.info("capabilities = " + capabilities);
652 if (caplevel != null && !caplevel.isEmpty()) {
653 JsonNode subCapabilities = capabilities.get(caplevel);
654 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
655 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
656 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
657 ctx.setAttribute("capabilities", "None");
658 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
659 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
660 log.info("getCapability Successful ");
663 if (findCapability != null && !findCapability.isEmpty()) {
664 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
665 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL))
666 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
668 ctx.setAttribute("capabilities", "Supported");
670 ctx.setAttribute("capabilities", "Not-Supported");
673 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
677 ctx.setAttribute(responsePrefix + "capabilities", capabilities.toString());
678 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
679 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
680 log.info("getCapability Successful ");
681 } catch (Exception e) {
682 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
683 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
684 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
685 log.error("Failed in getCapability " + e.getMessage());
687 throw new SvcLogicException(e.getMessage());
691 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
692 JsonNode subCapabilities) throws Exception {
693 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
695 if (subCapabilities.size() == 0) {
696 ctx.setAttribute("capabilities", "None");
697 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
700 JsonNode vmCaps = null;
701 for (JsonNode cap : subCapabilities) {
702 if (null != cap && null != cap.get(findCapability)
703 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
704 vmCaps = cap.get(findCapability);
705 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
710 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
711 ctx.setAttribute("capabilities", "Not-Supported");
712 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
716 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
717 if (StringUtils.isBlank(vnfcFunctionCode)) {
718 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
719 ctx.setAttribute("capabilities", "Not-Supported");
723 if (vmCaps.toString().contains(vnfcFunctionCode))
724 ctx.setAttribute("capabilities", "Supported");
726 ctx.setAttribute("capabilities", "Not-Supported");
727 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute("capabilities"));
730 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) throws Exception {
731 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
732 for (Object key : ctx.getAttributeKeySet()) {
733 String parmName = (String) key;
734 String parmValue = ctx.getAttribute(parmName);
735 log.info(parmName + "=" + parmValue);
738 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
739 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
740 return vnfcFunctionCode;
743 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
744 boolean capabilityCheckNeeded = true;
745 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
746 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<AppcDataServiceConstant.ACTIONS>(
747 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
748 for (AppcDataServiceConstant.ACTIONS action : actionList) {
749 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
750 capabilityCheckNeeded = false;
755 return capabilityCheckNeeded;