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 static final String CONFIG_FILES_PREFIX = "tmp.configFiles";
61 static final String MAX_CONF_FILE_PREFIX = "tmp.configfilesmax";
62 static final String UPLOAD_CONFIG_PREFIX = "tmp.uploadConfig";
63 static final String UPLOAD_CONFIG_INFO_PREFIX = "tmp.uploadConfigInfo";
65 static final String PREPARE_RELATIONSHIP_PARAM = "tmp.preparerel";
66 static final String CONFIG_FILE_ID_PARAM = "tmp.configfilesmax.configfileid";
67 static final String FILE_CATEGORY_PARAM = "file-category";
68 static final String UPLOAD_CONFIG_ID_PARAM = "tmp.uploadConfigInfo.UPLOAD-CONFIG-ID";
70 static final String SDC_IND = "N";
71 static final String TMP_CONVERTCONFIG_ESC_DATA = "tmp.convertconfig.escapeData";
72 static final String CONFIG_PARAMS = "configuration-params";
73 static final String TMP_MERGE_MERGED_DATA = "tmp.merge.mergedData";
74 static final String DATA_SOURCE = "data-source";
75 static final String FILE_CONTENT = "file-content";
76 static final String CAPABILITIES = "capabilities";
77 static final String NOT_SUPPORTED = "Not-Supported";
78 static final String UNABLE_TO_READ_STR = "Unable to Read ";
79 static final String UNABLE_TO_SAVE_RELATIONSHIP_STR = "Unable to save prepare_relationship";
82 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
83 private final DGGeneralDBService db;
86 * Constructor which provide default DB service
88 public ConfigResourceNode() {
89 db = DGGeneralDBService.initialise();
93 * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
95 public ConfigResourceNode(DGGeneralDBService dbService) {
99 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
101 log.info("Received getConfigFiles call with params : " + inParams);
102 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
105 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
106 QueryStatus status = db
107 .getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
109 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
110 throw new QueryException("Unable to Read ConfigFileReference:device-configuration");
113 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
115 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
116 throw new QueryException("Unable to Read ConfigFileReference:configuration_success");
119 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
121 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
122 throw new QueryException("Unable to Read ConfigFileReference:configuration_error");
125 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
127 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
128 throw new QueryException("Unable to Read ConfigFileReference:configuration_log");
131 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
132 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
133 log.info("GetConfigFileReference Successful ");
134 } catch (Exception e) {
135 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
136 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
137 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
138 log.error("Failed in GetConfigFileReference", e);
139 throw new SvcLogicException(e.getMessage());
143 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
145 log.info("Received getDeviceInfo call with params : " + inParams);
146 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
149 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
150 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, DEVICE_PROTOCOL_PREFIX);
152 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
153 throw new QueryException("Unable to Read device_interface_protocol");
156 status = db.getConfigureActionDGByVnfTypeNAction(ctx, CONF_ACTION_PREFIX);
157 if (status == QueryStatus.FAILURE) {
158 throw new QueryException("Unable to Read configure_action_dg");
161 if (status == QueryStatus.NOT_FOUND) {
162 status = db.getConfigureActionDGByVnfType(ctx, CONF_ACTION_PREFIX);
164 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
165 throw new QueryException("Unable to Read configure_action_dg");
169 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
170 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
171 log.info("getCommonConfigInfo Successful ");
172 } catch (Exception e) {
173 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
174 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
175 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
176 log.error("Failed in getCommonConfigInfo", e);
177 throw new SvcLogicException(e.getMessage());
182 * FileCategory can be config_template, parameter_definitions, parameter_yang
184 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
186 log.info("Received getTemplate call with params : " + inParams);
188 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
189 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
190 String templateName = ctx.getAttribute("template-name");
192 String responsePrefix1 = "";
196 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
197 log.info("RESPONSEPREFIX : " + responsePrefix);
198 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
200 if (StringUtils.isBlank(templateName)) {
201 status = db.getTemplate(ctx, responsePrefix, fileCategory);
202 if (status == QueryStatus.FAILURE) {
203 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
206 if (status == QueryStatus.NOT_FOUND) {
208 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
210 if (status == QueryStatus.FAILURE) {
211 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
214 if (status == QueryStatus.NOT_FOUND) {
215 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
220 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
222 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
223 throw new QueryException(UNABLE_TO_READ_STR + fileCategory + " template");
227 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
228 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
229 log.info("GetTemplate Successful ");
230 } catch (Exception e) {
231 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
232 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
233 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
234 log.error("Failed in getTemplate", e);
236 throw new SvcLogicException(e.getMessage());
240 void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
242 log.info("Received saveConfigFiles call with params : " + inParams);
244 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
248 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
249 QueryStatus status = db.saveConfigFiles(ctx, CONFIG_FILES_PREFIX);
251 if (status == QueryStatus.FAILURE) {
252 throw new QueryException("Unable to Save " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " in configfiles");
255 status = db.getMaxConfigFileId(ctx, MAX_CONF_FILE_PREFIX, ctx.getAttribute(FILE_CATEGORY_PARAM));
257 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
258 throw new QueryException(
259 "Unable to get " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " from configfiles");
262 status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
263 ctx.getAttribute(CONFIG_FILE_ID_PARAM), SDC_IND);
264 if (status == QueryStatus.FAILURE) {
265 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
268 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
269 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
270 log.info("saveConfigFiles Successful ");
271 } catch (Exception e) {
272 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
273 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
274 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
275 log.error("Failed in saveConfigFiles", e);
277 throw new SvcLogicException(e.getMessage());
281 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
283 log.info("Received updateUploadConfig call with params : " + inParams);
285 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
289 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
291 ctx.setAttribute("tmp.escaped.devicerunningconfig",
292 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
294 QueryStatus status = db.saveUploadConfig(ctx, UPLOAD_CONFIG_PREFIX);
296 if (status == QueryStatus.FAILURE) {
297 throw new QueryException("Unable to Save configuration in upload_config");
300 status = db.getUploadConfigInfo(ctx, UPLOAD_CONFIG_INFO_PREFIX);
302 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
303 throw new QueryException("Unable to get record from upload_config");
306 status = db.updateUploadConfig(ctx, UPLOAD_CONFIG_PREFIX,
307 Integer.parseInt(ctx.getAttribute(UPLOAD_CONFIG_ID_PARAM)));
308 if (status == QueryStatus.FAILURE)
309 throw new QueryException("Unable to upload upload_config");
311 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
312 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
313 log.info("updateUploadConfig 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 updateUploadConfig", e);
320 throw new SvcLogicException(e.getMessage());
324 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
326 log.info("Received savePrepareRelationship call with params : " + inParams);
328 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
329 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
330 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
333 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
335 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM, fileId, sdcArtifactInd);
336 if (status == QueryStatus.FAILURE) {
337 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
340 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
341 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
342 log.info("savePrepareRelationship Successful ");
343 } catch (Exception e) {
344 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
345 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
346 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
347 log.error("Failed in saveConfigFiles", e);
349 throw new SvcLogicException(e.getMessage());
353 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
355 log.info("Received saveConfigBlock call with params : " + inParams);
357 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
360 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
361 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA, EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
363 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
364 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
365 ctx.getAttribute("configuration"));
368 saveConfigurationBlock(inParams, ctx);
370 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
371 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
372 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
373 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
375 saveConfigurationData(inParams, ctx);
378 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
379 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
380 log.info("saveConfigBlock Successful ");
381 } catch (Exception e) {
382 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
383 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
384 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
385 log.error("Failed in saveConfigBlock", e);
387 throw new SvcLogicException(e.getMessage());
391 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
393 log.info("Received saveTemplateConfig call with params : " + inParams);
395 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
398 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
400 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
402 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
403 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
404 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
405 ctx.getAttribute("config-template.file-content"));
408 saveConfigurationData(inParams, ctx);
410 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
411 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
412 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
413 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
417 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
418 ctx.getAttribute("config-template.config-file-id"), "Y");
419 if (status == QueryStatus.FAILURE) {
420 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
423 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
424 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
425 log.info("saveTemplateConfig Successful ");
426 } catch (Exception e) {
427 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
428 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
429 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
430 log.error("Failed in saveTemplateConfig", e);
432 throw new SvcLogicException(e.getMessage());
436 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
438 log.info("Received saveStyleSheet call with params : " + inParams);
440 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
444 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
445 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
446 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
447 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
448 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
450 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
451 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
452 log.info("saveStyleSheet Successful ");
453 } catch (Exception e) {
454 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
455 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
456 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
457 log.error("Failed in saveStyleSheet", e);
459 throw new SvcLogicException(e.getMessage());
463 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
465 log.info("Received saveStyleSheet call with params : " + inParams);
467 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
468 String siteLocation = ctx.getAttribute("site-location");
474 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
476 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
478 if (status == QueryStatus.FAILURE) {
479 throw new QueryException("Unable to Read smm file");
482 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
484 if (status == QueryStatus.FAILURE) {
485 throw new QueryException("Unable to Read intermediate_ca_chain file");
488 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
491 if (status == QueryStatus.FAILURE) {
492 throw new QueryException("Unable to Read server_certificate_and_key file");
495 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
496 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
497 log.info("saveStyleSheet Successful ");
498 } catch (Exception e) {
499 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
500 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
501 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
502 log.error("Failed in saveStyleSheet", e);
504 throw new SvcLogicException(e.getMessage());
508 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
509 String fileContent, String deviceConfig) throws SvcLogicException {
510 ctx.setAttribute(DATA_SOURCE, dataSource);
511 ctx.setAttribute(FILE_CONTENT, fileContent);
512 ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
513 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
515 saveConfigFiles(inParams, ctx);
518 private void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
519 ctx.setAttribute(DATA_SOURCE, "Request");
520 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA));
521 ctx.setAttribute(FILE_CATEGORY_PARAM, "configuration_block");
522 saveConfigFiles(inParams, ctx);
525 private void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
526 ctx.setAttribute(DATA_SOURCE, ctx.getAttribute("originator-id"));
527 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(CONFIG_PARAMS));
528 ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
529 saveConfigFiles(inParams, ctx);
532 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
533 throws SvcLogicException {
535 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
537 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
538 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
539 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
540 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
542 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
544 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
545 throw new QueryException("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
548 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
549 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
550 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
551 log.info("getConfigFilesByVnfVmNCategory Successful "
552 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
553 } catch (Exception e) {
554 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
555 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
556 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
557 log.error("Failed in getConfigFilesByVnfVmNCategory", e);
559 throw new SvcLogicException(e.getMessage());
563 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
564 throws SvcLogicException {
566 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
568 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
570 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
572 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
573 throw new QueryException("Unable to get download config template.");
576 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
577 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
578 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
579 log.info("getDownloadConfigTemplateByVnf Successful "
580 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
581 } catch (Exception e) {
582 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
583 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
584 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
585 log.error("Failed in getDownloadConfigTemplateByVnf", e);
587 throw new SvcLogicException(e.getMessage());
591 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
593 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
595 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
596 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
600 SvcLogicContext logctx = new SvcLogicContext();
601 String escapedMessage = EscapeUtils.escapeSql(message);
603 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
604 logctx.setAttribute("log-message-type", messageType);
605 logctx.setAttribute("log-message", escapedMessage);
607 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
608 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
610 logctx.setAttribute("log-message", null);
612 if (status == QueryStatus.FAILURE) {
613 throw new QueryException("Unable to insert into config_transaction_log");
616 } catch (Exception e) {
617 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
618 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
619 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
620 log.error("Failed in saveConfigTransactionLog", e);
621 throw new SvcLogicException(e.getMessage());
625 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
627 log.info("Received getVnfcReference call with params : " + inParams);
629 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
633 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
634 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
636 if (status == QueryStatus.FAILURE) {
637 throw new QueryException("Unable to Read vnfc-reference");
640 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
642 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
643 throw new QueryException("Unable to Read vnfc reference");
646 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
647 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
648 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
649 log.info("getVnfcReference Successful ");
650 } catch (Exception e) {
651 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
652 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
653 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
654 log.error("Failed in getVnfcReference", e);
656 throw new SvcLogicException(e.getMessage());
660 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
661 log.info("Received getCapability call with params : " + inParams);
662 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
663 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
664 String caplevel = inParams.get("caplevel");
665 String findCapability = inParams.get("checkCapability");
666 String vServerId = inParams.get("vServerId");
667 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
668 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
669 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
670 log.info("getCapability Successful - No need for capability check for this action");
674 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
675 log.info("getCapability::returned from DB::+cap");
676 if (StringUtils.isBlank(cap)) {
677 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
678 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
679 log.info("getCapability Successful - No capability blocks found");
682 ObjectMapper mapper = new ObjectMapper();
683 JsonNode caps = mapper.readTree(cap);
684 log.info("From DB = " + caps);
685 JsonNode capabilities = caps.get(CAPABILITIES);
686 log.info("capabilities = " + capabilities);
687 if (caplevel != null && !caplevel.isEmpty()) {
688 JsonNode subCapabilities = capabilities.get(caplevel);
689 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
690 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
691 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
692 ctx.setAttribute(CAPABILITIES, "None");
693 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
694 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
695 log.info("getCapability Successful ");
698 if (findCapability != null && !findCapability.isEmpty()) {
699 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
700 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
701 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
703 ctx.setAttribute(CAPABILITIES, "Supported");
706 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
709 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
713 ctx.setAttribute(responsePrefix + CAPABILITIES, capabilities.toString());
715 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
716 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
717 log.info("getCapability Successful ");
718 } catch (Exception e) {
719 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
720 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
721 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
722 log.error("Failed in getCapability", e);
724 throw new SvcLogicException(e.getMessage());
728 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
729 JsonNode subCapabilities) {
730 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
732 if (subCapabilities.size() == 0) {
733 ctx.setAttribute(CAPABILITIES, "None");
734 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
737 JsonNode vmCaps = null;
738 for (JsonNode cap : subCapabilities) {
739 if (null != cap && null != cap.get(findCapability)
740 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
741 vmCaps = cap.get(findCapability);
742 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
747 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
748 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
749 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
753 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
754 if (StringUtils.isBlank(vnfcFunctionCode)) {
755 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
756 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
760 if (vmCaps.toString().contains(vnfcFunctionCode)) {
761 ctx.setAttribute(CAPABILITIES, "Supported");
763 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
765 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute(CAPABILITIES));
768 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) {
769 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
770 for (Object key : ctx.getAttributeKeySet()) {
771 String parmName = (String) key;
772 String parmValue = ctx.getAttribute(parmName);
773 log.info(parmName + "=" + parmValue);
776 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
777 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
778 return vnfcFunctionCode;
781 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
782 boolean capabilityCheckNeeded = true;
783 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
784 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<>(
785 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
786 for (AppcDataServiceConstant.ACTIONS action : actionList) {
787 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
788 capabilityCheckNeeded = false;
793 return capabilityCheckNeeded;