2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 static final String SITE_LOCATION_PARAM = "site-location";
84 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
85 private final DGGeneralDBService db;
88 * Constructor which provide default DB service
90 public ConfigResourceNode() {
91 db = DGGeneralDBService.initialise();
95 * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
97 public ConfigResourceNode(DGGeneralDBService dbService) {
101 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
103 log.info("Received getConfigFiles call with params : " + inParams);
104 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
107 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
108 QueryStatus status = db
109 .getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
111 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
112 throw new QueryException("Unable to Read ConfigFileReference:device-configuration");
115 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
117 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
118 throw new QueryException("Unable to Read ConfigFileReference:configuration_success");
121 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
123 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
124 throw new QueryException("Unable to Read ConfigFileReference:configuration_error");
127 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
129 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
130 throw new QueryException("Unable to Read ConfigFileReference:configuration_log");
133 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
134 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
135 log.info("GetConfigFileReference Successful ");
136 } catch (Exception e) {
137 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
138 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
139 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
140 log.error("Failed in GetConfigFileReference", e);
141 throw new SvcLogicException(e.getMessage());
145 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
147 log.info("Received getDeviceInfo call with params : " + inParams);
148 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
151 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
152 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, DEVICE_PROTOCOL_PREFIX);
154 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
155 throw new QueryException("Unable to Read device_interface_protocol");
158 status = db.getConfigureActionDGByVnfTypeNAction(ctx, CONF_ACTION_PREFIX);
159 if (status == QueryStatus.FAILURE) {
160 throw new QueryException("Unable to Read configure_action_dg");
163 if (status == QueryStatus.NOT_FOUND) {
164 status = db.getConfigureActionDGByVnfType(ctx, CONF_ACTION_PREFIX);
166 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
167 throw new QueryException("Unable to Read configure_action_dg");
171 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
172 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
173 log.info("getCommonConfigInfo Successful ");
174 } catch (Exception e) {
175 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
176 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
177 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
178 log.error("Failed in getCommonConfigInfo", e);
179 throw new SvcLogicException(e.getMessage());
184 * FileCategory can be config_template, parameter_definitions, parameter_yang
186 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
188 log.info("Received getTemplate call with params : " + inParams);
190 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
191 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
192 String templateName = ctx.getAttribute("template-name");
193 String templateModelId = ctx.getAttribute("template-model-id");
195 String responsePrefix1 = "";
199 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
200 log.info("RESPONSEPREFIX : " + responsePrefix);
201 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
203 if (StringUtils.isBlank(templateName)) {
204 if (StringUtils.isNotBlank(templateModelId)) {
205 status = db.getTemplateWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId);
206 if (status == QueryStatus.FAILURE) {
207 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
209 if (!(status == QueryStatus.NOT_FOUND) ) {
210 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
211 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
212 log.info("GetTemplate Successful ");
216 status = db.getTemplate(ctx, responsePrefix, fileCategory);
217 if (status == QueryStatus.FAILURE) {
218 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
221 if (status == QueryStatus.NOT_FOUND) {
222 if (StringUtils.isNotBlank(templateModelId)) {
223 status = db.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId);
224 if (status == QueryStatus.FAILURE) {
225 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
227 if (!(status == QueryStatus.NOT_FOUND) ) {
228 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
229 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
230 log.info("GetTemplate Successful ");
234 if (status == QueryStatus.NOT_FOUND) {
237 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
239 if (status == QueryStatus.FAILURE) {
240 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
243 if (status == QueryStatus.NOT_FOUND) {
244 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
252 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
254 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
255 throw new QueryException(UNABLE_TO_READ_STR + fileCategory + " template");
259 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
260 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
261 log.info("GetTemplate Successful ");
262 } catch (Exception e) {
263 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
264 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
265 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
266 log.error("Failed in getTemplate", e);
268 throw new SvcLogicException(e.getMessage());
272 void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
274 log.info("Received saveConfigFiles call with params : " + inParams);
276 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
280 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
281 QueryStatus status = db.saveConfigFiles(ctx, CONFIG_FILES_PREFIX);
283 if (status == QueryStatus.FAILURE) {
284 throw new QueryException("Unable to Save " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " in configfiles");
287 status = db.getMaxConfigFileId(ctx, MAX_CONF_FILE_PREFIX, ctx.getAttribute(FILE_CATEGORY_PARAM));
289 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
290 throw new QueryException(
291 "Unable to get " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " from configfiles");
294 status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
295 ctx.getAttribute(CONFIG_FILE_ID_PARAM), SDC_IND);
296 if (status == QueryStatus.FAILURE) {
297 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
300 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
301 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
302 log.info("saveConfigFiles Successful ");
303 } catch (Exception e) {
304 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
305 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
306 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
307 log.error("Failed in saveConfigFiles", e);
309 throw new SvcLogicException(e.getMessage());
313 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
315 log.info("Received updateUploadConfig call with params : " + inParams);
317 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
321 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
323 ctx.setAttribute("tmp.escaped.devicerunningconfig",
324 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
326 QueryStatus status = db.saveUploadConfig(ctx, UPLOAD_CONFIG_PREFIX);
328 if (status == QueryStatus.FAILURE) {
329 throw new QueryException("Unable to Save configuration in upload_config");
332 status = db.getUploadConfigInfo(ctx, UPLOAD_CONFIG_INFO_PREFIX);
334 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
335 throw new QueryException("Unable to get record from upload_config");
338 status = db.updateUploadConfig(ctx, UPLOAD_CONFIG_PREFIX,
339 Integer.parseInt(ctx.getAttribute(UPLOAD_CONFIG_ID_PARAM)));
340 if (status == QueryStatus.FAILURE)
341 throw new QueryException("Unable to upload upload_config");
343 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
344 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
345 log.info("updateUploadConfig Successful ");
346 } catch (Exception e) {
347 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
348 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
349 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
350 log.error("Failed in updateUploadConfig", e);
352 throw new SvcLogicException(e.getMessage());
356 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
358 log.info("Received savePrepareRelationship call with params : " + inParams);
360 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
361 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
362 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
365 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
367 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM, fileId, sdcArtifactInd);
368 if (status == QueryStatus.FAILURE) {
369 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
372 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
373 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
374 log.info("savePrepareRelationship Successful ");
375 } catch (Exception e) {
376 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
377 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
378 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
379 log.error("Failed in saveConfigFiles", e);
381 throw new SvcLogicException(e.getMessage());
385 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
387 log.info("Received saveConfigBlock call with params : " + inParams);
389 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
392 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
393 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA, EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
395 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
396 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
397 ctx.getAttribute("configuration"));
400 saveConfigurationBlock(inParams, ctx);
402 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
403 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
404 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
405 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
407 saveConfigurationData(inParams, ctx);
410 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
411 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
412 log.info("saveConfigBlock Successful ");
413 } catch (Exception e) {
414 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
415 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
416 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
417 log.error("Failed in saveConfigBlock", e);
419 throw new SvcLogicException(e.getMessage());
423 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
425 log.info("Received saveTemplateConfig call with params : " + inParams);
427 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
430 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
432 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
434 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
435 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
436 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
437 ctx.getAttribute("config-template.file-content"));
440 saveConfigurationData(inParams, ctx);
442 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
443 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
444 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
445 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
449 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
450 ctx.getAttribute("config-template.config-file-id"), "Y");
451 if (status == QueryStatus.FAILURE) {
452 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
455 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
456 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
457 log.info("saveTemplateConfig Successful ");
458 } catch (Exception e) {
459 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
460 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
461 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
462 log.error("Failed in saveTemplateConfig", e);
464 throw new SvcLogicException(e.getMessage());
468 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
470 log.info("Received saveStyleSheet call with params : " + inParams);
472 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
476 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
477 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
478 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
479 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
480 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
482 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
483 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
484 log.info("saveStyleSheet Successful ");
485 } catch (Exception e) {
486 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
487 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
488 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
489 log.error("Failed in saveStyleSheet", e);
491 throw new SvcLogicException(e.getMessage());
495 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
497 log.info("Received saveStyleSheet call with params : " + inParams);
499 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
500 String siteLocation = ctx.getAttribute(SITE_LOCATION_PARAM);
506 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
508 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
510 if (status == QueryStatus.FAILURE) {
511 throw new QueryException("Unable to Read smm file");
514 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
516 if (status == QueryStatus.FAILURE) {
517 throw new QueryException("Unable to Read intermediate_ca_chain file");
520 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
523 if (status == QueryStatus.FAILURE) {
524 throw new QueryException("Unable to Read server_certificate_and_key file");
527 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
528 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
529 log.info("saveStyleSheet Successful ");
530 } catch (Exception e) {
531 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
532 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
533 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
534 log.error("Failed in saveStyleSheet", e);
536 throw new SvcLogicException(e.getMessage());
540 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
541 String fileContent, String deviceConfig) throws SvcLogicException {
542 ctx.setAttribute(DATA_SOURCE, dataSource);
543 ctx.setAttribute(FILE_CONTENT, fileContent);
544 ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
545 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
547 saveConfigFiles(inParams, ctx);
550 private void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
551 ctx.setAttribute(DATA_SOURCE, "Request");
552 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA));
553 ctx.setAttribute(FILE_CATEGORY_PARAM, "configuration_block");
554 saveConfigFiles(inParams, ctx);
557 private void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
558 ctx.setAttribute(DATA_SOURCE, ctx.getAttribute("originator-id"));
559 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(CONFIG_PARAMS));
560 ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
561 saveConfigFiles(inParams, ctx);
564 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
565 throws SvcLogicException {
567 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
569 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
570 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
571 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
572 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
574 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
576 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
577 throw new QueryException("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
580 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
581 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
582 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
583 log.info("getConfigFilesByVnfVmNCategory Successful "
584 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
585 } catch (Exception e) {
586 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
587 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
588 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
589 log.error("Failed in getConfigFilesByVnfVmNCategory", e);
591 throw new SvcLogicException(e.getMessage());
595 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
596 throws SvcLogicException {
598 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
600 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
602 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
604 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
605 throw new QueryException("Unable to get download config template.");
608 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
609 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
610 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
611 log.info("getDownloadConfigTemplateByVnf Successful "
612 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
613 } catch (Exception e) {
614 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
615 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
616 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
617 log.error("Failed in getDownloadConfigTemplateByVnf", e);
619 throw new SvcLogicException(e.getMessage());
623 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
625 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
627 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
628 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
632 SvcLogicContext logctx = new SvcLogicContext();
633 String escapedMessage = EscapeUtils.escapeSql(message);
635 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
636 logctx.setAttribute("log-message-type", messageType);
637 logctx.setAttribute("log-message", escapedMessage);
639 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
640 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
642 logctx.setAttribute("log-message", null);
644 if (status == QueryStatus.FAILURE) {
645 throw new QueryException("Unable to insert into config_transaction_log");
648 } catch (Exception e) {
649 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
650 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
651 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
652 log.error("Failed in saveConfigTransactionLog", e);
653 throw new SvcLogicException(e.getMessage());
657 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
659 log.info("Received getVnfcReference call with params : " + inParams);
661 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
662 String templateModelId = ctx.getAttribute("template-model-id");
663 log.info("getVnfcReference():::"+templateModelId);
664 QueryStatus status = null;
667 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
670 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
672 if (status == QueryStatus.FAILURE) {
673 throw new QueryException("Unable to Read vnfc-reference");
677 if (StringUtils.isNotBlank(templateModelId)) {
678 status = db.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix,templateModelId);
679 if (status == QueryStatus.FAILURE) {
680 throw new QueryException("Unable to Read vnfc-reference with template-model-id");
683 if (StringUtils.isBlank(templateModelId) || (StringUtils.isNotBlank(templateModelId) && (status == QueryStatus.NOT_FOUND))) {
684 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
686 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
687 throw new QueryException("Unable to Read vnfc reference");
691 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
692 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
693 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
694 log.info("getVnfcReference Successful ");
695 } catch (Exception e) {
696 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
697 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
698 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
699 log.error("Failed in getVnfcReference", e);
701 throw new SvcLogicException(e.getMessage());
705 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
706 log.info("Received getCapability call with params : " + inParams);
707 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
708 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
709 String caplevel = inParams.get("caplevel");
710 String findCapability = inParams.get("checkCapability");
711 String vServerId = inParams.get("vServerId");
712 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
713 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
714 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
715 log.info("getCapability Successful - No need for capability check for this action");
719 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
720 log.info("getCapability::returned from DB::+cap");
721 if (StringUtils.isBlank(cap)) {
722 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
723 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
724 log.info("getCapability Successful - No capability blocks found");
727 ObjectMapper mapper = new ObjectMapper();
728 JsonNode caps = mapper.readTree(cap);
729 log.info("From DB = " + caps);
730 JsonNode capabilities = caps.get(CAPABILITIES);
731 log.info("capabilities = " + capabilities);
732 if (caplevel != null && !caplevel.isEmpty()) {
733 JsonNode subCapabilities = capabilities.get(caplevel);
734 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
735 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
736 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
737 ctx.setAttribute(CAPABILITIES, "None");
738 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
739 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
740 log.info("getCapability Successful ");
743 if (findCapability != null && !findCapability.isEmpty()) {
744 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
745 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
746 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
748 ctx.setAttribute(CAPABILITIES, "Supported");
751 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
754 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
758 ctx.setAttribute(responsePrefix + CAPABILITIES, capabilities.toString());
760 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
761 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
762 log.info("getCapability Successful ");
763 } catch (Exception e) {
764 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
765 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
766 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
767 log.error("Failed in getCapability", e);
769 throw new SvcLogicException(e.getMessage());
773 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
774 JsonNode subCapabilities) {
775 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
777 if (subCapabilities.size() == 0) {
778 ctx.setAttribute(CAPABILITIES, "None");
779 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
782 JsonNode vmCaps = null;
783 for (JsonNode cap : subCapabilities) {
784 if (null != cap && null != cap.get(findCapability)
785 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
786 vmCaps = cap.get(findCapability);
787 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
792 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
793 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
794 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
798 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
799 if (StringUtils.isBlank(vnfcFunctionCode)) {
800 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
801 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
805 if (vmCaps.toString().contains(vnfcFunctionCode)) {
806 ctx.setAttribute(CAPABILITIES, "Supported");
808 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
810 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute(CAPABILITIES));
813 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) {
814 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
815 for (Object key : ctx.getAttributeKeySet()) {
816 String parmName = (String) key;
817 String parmValue = ctx.getAttribute(parmName);
818 log.info(parmName + "=" + parmValue);
821 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
822 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
823 return vnfcFunctionCode;
826 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
827 boolean capabilityCheckNeeded = true;
828 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
829 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<>(
830 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
831 for (AppcDataServiceConstant.ACTIONS action : actionList) {
832 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
833 capabilityCheckNeeded = false;
838 return capabilityCheckNeeded;