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 * ============LICENSE_END=========================================================
23 package org.onap.appc.data.services.node;
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
27 import com.fasterxml.jackson.databind.JsonNode;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.List;
33 import org.apache.commons.lang3.StringUtils;
34 import org.onap.appc.data.services.AppcDataServiceConstant;
35 import org.onap.appc.data.services.db.DGGeneralDBService;
36 import org.onap.appc.data.services.utils.EscapeUtils;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
42 public class ConfigResourceNode implements SvcLogicJavaPlugin {
44 static final String DEVICE_CONF_PREFIX = "configfilereference-deviceconfig";
45 static final String DEVICE_CONF_FILE_TYPE = "device_configuration";
47 static final String SUCCESS_PREFIX = "configfilereference-success";
48 static final String SUCCESS_FILE_TYPE = "configuration_success";
50 static final String FAILURE_PREFIX = "configfilereference-failure";
51 static final String FAILURE_FILE_TYPE = "configuration_error";
53 static final String LOG_PREFIX = "configfilereference-log";
54 static final String LOG_FILE_TYPE = "log";
56 static final String DEVICE_PROTOCOL_PREFIX = "tmp.deviceinterfaceprotocol";
57 static final String CONF_ACTION_PREFIX = "tmp.configureactiondg";
59 static final String CONFIG_FILES_PREFIX = "tmp.configFiles";
60 static final String MAX_CONF_FILE_PREFIX = "tmp.configfilesmax";
61 static final String UPLOAD_CONFIG_PREFIX = "tmp.uploadConfig";
62 static final String UPLOAD_CONFIG_INFO_PREFIX = "tmp.uploadConfigInfo";
64 static final String PREPARE_RELATIONSHIP_PARAM = "tmp.preparerel";
65 static final String CONFIG_FILE_ID_PARAM = "tmp.configfilesmax.configfileid";
66 static final String FILE_CATEGORY_PARAM = "file-category";
67 static final String UPLOAD_CONFIG_ID_PARAM = "tmp.uploadConfigInfo.UPLOAD-CONFIG-ID";
69 static final String SDC_IND = "N";
70 static final String TMP_CONVERTCONFIG_ESC_DATA = "tmp.convertconfig.escapeData";
71 static final String CONFIG_PARAMS = "configuration-params";
72 static final String TMP_MERGE_MERGED_DATA = "tmp.merge.mergedData";
73 static final String DATA_SOURCE = "data-source";
74 static final String FILE_CONTENT = "file-content";
75 static final String CAPABILITIES = "capabilities";
76 static final String NOT_SUPPORTED = "Not-Supported";
77 static final String UNABLE_TO_READ_STR = "Unable to Read ";
78 static final String UNABLE_TO_SAVE_RELATIONSHIP_STR = "Unable to save prepare_relationship";
81 static final String SITE_LOCATION_PARAM = "site-location";
83 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
84 private final DGGeneralDBService db;
87 * Constructor which provide default DB service
89 public ConfigResourceNode() {
90 db = DGGeneralDBService.initialise();
94 * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
96 public ConfigResourceNode(DGGeneralDBService dbService) {
100 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
102 log.info("Received getConfigFiles call with params : " + inParams);
103 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
106 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
107 QueryStatus status = db
108 .getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
110 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
111 throw new QueryException("Unable to Read ConfigFileReference:device-configuration");
114 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
116 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
117 throw new QueryException("Unable to Read ConfigFileReference:configuration_success");
120 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
122 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
123 throw new QueryException("Unable to Read ConfigFileReference:configuration_error");
126 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
128 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
129 throw new QueryException("Unable to Read ConfigFileReference:configuration_log");
132 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
133 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
134 log.info("GetConfigFileReference Successful ");
135 } catch (Exception e) {
136 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
137 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
138 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
139 log.error("Failed in GetConfigFileReference", e);
140 throw new SvcLogicException(e.getMessage());
144 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
146 log.info("Received getDeviceInfo call with params : " + inParams);
147 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
150 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
151 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, DEVICE_PROTOCOL_PREFIX);
153 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
154 throw new QueryException("Unable to Read device_interface_protocol");
157 status = db.getConfigureActionDGByVnfTypeNAction(ctx, CONF_ACTION_PREFIX);
158 if (status == QueryStatus.FAILURE) {
159 throw new QueryException("Unable to Read configure_action_dg");
162 if (status == QueryStatus.NOT_FOUND) {
163 status = db.getConfigureActionDGByVnfType(ctx, CONF_ACTION_PREFIX);
165 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
166 throw new QueryException("Unable to Read configure_action_dg");
170 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
171 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
172 log.info("getCommonConfigInfo Successful ");
173 } catch (Exception e) {
174 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
175 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
176 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
177 log.error("Failed in getCommonConfigInfo", e);
178 throw new SvcLogicException(e.getMessage());
183 * FileCategory can be config_template, parameter_definitions, parameter_yang
185 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
187 log.info("Received getTemplate call with params : " + inParams);
189 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
190 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
191 String templateName = ctx.getAttribute("template-name");
192 String templateModelId = ctx.getAttribute("template-model-id");
194 String responsePrefix1 = "";
198 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
199 log.info("RESPONSEPREFIX : " + responsePrefix);
200 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
202 if (StringUtils.isBlank(templateName)) {
203 if (StringUtils.isNotBlank(templateModelId)) {
204 status = db.getTemplateWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId);
205 if (status == QueryStatus.FAILURE) {
206 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
208 if (!(status == QueryStatus.NOT_FOUND) ) {
209 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
210 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
211 log.info("GetTemplate Successful ");
215 status = db.getTemplate(ctx, responsePrefix, fileCategory);
216 if (status == QueryStatus.FAILURE) {
217 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
220 if (status == QueryStatus.NOT_FOUND) {
221 if (StringUtils.isNotBlank(templateModelId)) {
222 status = db.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId);
223 if (status == QueryStatus.FAILURE) {
224 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
226 if (!(status == QueryStatus.NOT_FOUND) ) {
227 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
228 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
229 log.info("GetTemplate Successful ");
233 if (status == QueryStatus.NOT_FOUND) {
236 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
238 if (status == QueryStatus.FAILURE) {
239 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
242 if (status == QueryStatus.NOT_FOUND) {
243 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
251 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
253 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
254 throw new QueryException(UNABLE_TO_READ_STR + fileCategory + " template");
258 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
259 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
260 log.info("GetTemplate Successful ");
261 } catch (Exception e) {
262 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
263 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
264 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
265 log.error("Failed in getTemplate", e);
267 throw new SvcLogicException(e.getMessage());
271 void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
273 log.info("Received saveConfigFiles call with params : " + inParams);
275 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
279 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
280 QueryStatus status = db.saveConfigFiles(ctx, CONFIG_FILES_PREFIX);
282 if (status == QueryStatus.FAILURE) {
283 throw new QueryException("Unable to Save " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " in configfiles");
286 status = db.getMaxConfigFileId(ctx, MAX_CONF_FILE_PREFIX, ctx.getAttribute(FILE_CATEGORY_PARAM));
288 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
289 throw new QueryException(
290 "Unable to get " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " from configfiles");
293 status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
294 ctx.getAttribute(CONFIG_FILE_ID_PARAM), SDC_IND);
295 if (status == QueryStatus.FAILURE) {
296 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
299 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
300 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
301 log.info("saveConfigFiles Successful ");
302 } catch (Exception e) {
303 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
304 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
305 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
306 log.error("Failed in saveConfigFiles", e);
308 throw new SvcLogicException(e.getMessage());
312 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
314 log.info("Received updateUploadConfig call with params : " + inParams);
316 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
320 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
322 ctx.setAttribute("tmp.escaped.devicerunningconfig",
323 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
325 QueryStatus status = db.saveUploadConfig(ctx, UPLOAD_CONFIG_PREFIX);
327 if (status == QueryStatus.FAILURE) {
328 throw new QueryException("Unable to Save configuration in upload_config");
331 status = db.getUploadConfigInfo(ctx, UPLOAD_CONFIG_INFO_PREFIX);
333 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
334 throw new QueryException("Unable to get record from upload_config");
337 status = db.updateUploadConfig(ctx, UPLOAD_CONFIG_PREFIX,
338 Integer.parseInt(ctx.getAttribute(UPLOAD_CONFIG_ID_PARAM)));
339 if (status == QueryStatus.FAILURE)
340 throw new QueryException("Unable to upload upload_config");
342 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
343 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
344 log.info("updateUploadConfig Successful ");
345 } catch (Exception e) {
346 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
347 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
348 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
349 log.error("Failed in updateUploadConfig", e);
351 throw new SvcLogicException(e.getMessage());
355 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
357 log.info("Received savePrepareRelationship call with params : " + inParams);
359 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
360 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
361 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
364 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
366 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM, fileId, sdcArtifactInd);
367 if (status == QueryStatus.FAILURE) {
368 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
371 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
372 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
373 log.info("savePrepareRelationship Successful ");
374 } catch (Exception e) {
375 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
376 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
377 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
378 log.error("Failed in saveConfigFiles", e);
380 throw new SvcLogicException(e.getMessage());
384 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
386 log.info("Received saveConfigBlock call with params : " + inParams);
388 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
391 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
392 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA, EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
394 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
395 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
396 ctx.getAttribute("configuration"));
399 saveConfigurationBlock(inParams, ctx);
401 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
402 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
403 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
404 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
406 saveConfigurationData(inParams, ctx);
409 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
410 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
411 log.info("saveConfigBlock Successful ");
412 } catch (Exception e) {
413 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
414 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
415 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
416 log.error("Failed in saveConfigBlock", e);
418 throw new SvcLogicException(e.getMessage());
422 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
424 log.info("Received saveTemplateConfig call with params : " + inParams);
426 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
429 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
431 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
433 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
434 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
435 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
436 ctx.getAttribute("config-template.file-content"));
439 saveConfigurationData(inParams, ctx);
441 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
442 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
443 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
444 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
448 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
449 ctx.getAttribute("config-template.config-file-id"), "Y");
450 if (status == QueryStatus.FAILURE) {
451 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
454 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
455 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
456 log.info("saveTemplateConfig Successful ");
457 } catch (Exception e) {
458 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
459 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
460 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
461 log.error("Failed in saveTemplateConfig", e);
463 throw new SvcLogicException(e.getMessage());
467 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
469 log.info("Received saveStyleSheet call with params : " + inParams);
471 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
475 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
476 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
477 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
478 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
479 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
481 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
482 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
483 log.info("saveStyleSheet Successful ");
484 } catch (Exception e) {
485 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
486 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
487 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
488 log.error("Failed in saveStyleSheet", e);
490 throw new SvcLogicException(e.getMessage());
494 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
496 log.info("Received saveStyleSheet call with params : " + inParams);
498 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
499 String siteLocation = ctx.getAttribute(SITE_LOCATION_PARAM);
505 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
507 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
509 if (status == QueryStatus.FAILURE) {
510 throw new QueryException("Unable to Read smm file");
513 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
515 if (status == QueryStatus.FAILURE) {
516 throw new QueryException("Unable to Read intermediate_ca_chain file");
519 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
522 if (status == QueryStatus.FAILURE) {
523 throw new QueryException("Unable to Read server_certificate_and_key file");
526 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
527 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
528 log.info("saveStyleSheet Successful ");
529 } catch (Exception e) {
530 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
531 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
532 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
533 log.error("Failed in saveStyleSheet", e);
535 throw new SvcLogicException(e.getMessage());
539 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
540 String fileContent, String deviceConfig) throws SvcLogicException {
541 ctx.setAttribute(DATA_SOURCE, dataSource);
542 ctx.setAttribute(FILE_CONTENT, fileContent);
543 ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
544 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
546 saveConfigFiles(inParams, ctx);
549 private void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
550 ctx.setAttribute(DATA_SOURCE, "Request");
551 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA));
552 ctx.setAttribute(FILE_CATEGORY_PARAM, "configuration_block");
553 saveConfigFiles(inParams, ctx);
556 private void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
557 ctx.setAttribute(DATA_SOURCE, ctx.getAttribute("originator-id"));
558 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(CONFIG_PARAMS));
559 ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
560 saveConfigFiles(inParams, ctx);
563 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
564 throws SvcLogicException {
566 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
568 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
569 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
570 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
571 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
573 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
575 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
576 throw new QueryException("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
579 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
580 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
581 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
582 log.info("getConfigFilesByVnfVmNCategory Successful "
583 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
584 } catch (Exception e) {
585 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
586 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
587 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
588 log.error("Failed in getConfigFilesByVnfVmNCategory", e);
590 throw new SvcLogicException(e.getMessage());
594 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
595 throws SvcLogicException {
597 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
599 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
601 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
603 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
604 throw new QueryException("Unable to get download config template.");
607 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
608 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
609 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
610 log.info("getDownloadConfigTemplateByVnf Successful "
611 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
612 } catch (Exception e) {
613 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
614 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
615 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
616 log.error("Failed in getDownloadConfigTemplateByVnf", e);
618 throw new SvcLogicException(e.getMessage());
622 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
624 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
626 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
627 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
631 SvcLogicContext logctx = new SvcLogicContext();
632 String escapedMessage = EscapeUtils.escapeSql(message);
634 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
635 logctx.setAttribute("log-message-type", messageType);
636 logctx.setAttribute("log-message", escapedMessage);
638 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
639 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
641 logctx.setAttribute("log-message", null);
643 if (status == QueryStatus.FAILURE) {
644 throw new QueryException("Unable to insert into config_transaction_log");
647 } catch (Exception e) {
648 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
649 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
650 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
651 log.error("Failed in saveConfigTransactionLog", e);
652 throw new SvcLogicException(e.getMessage());
656 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
658 log.info("Received getVnfcReference call with params : " + inParams);
660 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
661 String templateModelId = ctx.getAttribute("template-model-id");
662 log.info("getVnfcReference():::"+templateModelId);
663 QueryStatus status = null;
666 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
669 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
671 if (status == QueryStatus.FAILURE) {
672 throw new QueryException("Unable to Read vnfc-reference");
676 if (StringUtils.isNotBlank(templateModelId)) {
677 status = db.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix,templateModelId);
678 if (status == QueryStatus.FAILURE) {
679 throw new QueryException("Unable to Read vnfc-reference with template-model-id");
682 if (StringUtils.isBlank(templateModelId) || (StringUtils.isNotBlank(templateModelId) && (status == QueryStatus.NOT_FOUND))) {
683 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
685 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
686 throw new QueryException("Unable to Read vnfc reference");
690 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
691 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
692 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
693 log.info("getVnfcReference Successful ");
694 } catch (Exception e) {
695 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
696 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
697 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
698 log.error("Failed in getVnfcReference", e);
700 throw new SvcLogicException(e.getMessage());
704 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
705 log.info("Received getCapability call with params : " + inParams);
706 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
707 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
708 String caplevel = inParams.get("caplevel");
709 String findCapability = inParams.get("checkCapability");
710 String vServerId = inParams.get("vServerId");
711 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
712 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
713 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
714 log.info("getCapability Successful - No need for capability check for this action");
718 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
719 log.info("getCapability::returned from DB::+cap");
720 if (StringUtils.isBlank(cap)) {
721 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
722 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
723 log.info("getCapability Successful - No capability blocks found");
726 ObjectMapper mapper = new ObjectMapper();
727 JsonNode caps = mapper.readTree(cap);
728 log.info("From DB = " + caps);
729 JsonNode capabilities = caps.get(CAPABILITIES);
730 log.info("capabilities = " + capabilities);
731 if (caplevel != null && !caplevel.isEmpty()) {
732 JsonNode subCapabilities = capabilities.get(caplevel);
733 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
734 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
735 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
736 ctx.setAttribute(CAPABILITIES, "None");
737 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
738 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
739 log.info("getCapability Successful ");
742 if (findCapability != null && !findCapability.isEmpty()) {
743 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
744 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
745 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
747 ctx.setAttribute(CAPABILITIES, "Supported");
750 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
753 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
757 ctx.setAttribute(responsePrefix + CAPABILITIES, capabilities.toString());
759 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
760 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
761 log.info("getCapability Successful ");
762 } catch (Exception e) {
763 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
764 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
765 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
766 log.error("Failed in getCapability", e);
768 throw new SvcLogicException(e.getMessage());
772 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
773 JsonNode subCapabilities) {
774 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
776 if (subCapabilities.size() == 0) {
777 ctx.setAttribute(CAPABILITIES, "None");
778 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
781 JsonNode vmCaps = null;
782 for (JsonNode cap : subCapabilities) {
783 if (null != cap && null != cap.get(findCapability)
784 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
785 vmCaps = cap.get(findCapability);
786 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
791 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
792 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
793 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
797 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
798 if (StringUtils.isBlank(vnfcFunctionCode)) {
799 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
800 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
804 if (vmCaps.toString().contains(vnfcFunctionCode)) {
805 ctx.setAttribute(CAPABILITIES, "Supported");
807 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
809 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute(CAPABILITIES));
812 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) {
813 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
814 for (Object key : ctx.getAttributeKeySet()) {
815 String parmName = (String) key;
816 String parmValue = ctx.getAttribute(parmName);
817 log.info(parmName + "=" + parmValue);
820 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
821 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
822 return vnfcFunctionCode;
825 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
826 boolean capabilityCheckNeeded = true;
827 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
828 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<>(
829 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
830 for (AppcDataServiceConstant.ACTIONS action : actionList) {
831 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
832 capabilityCheckNeeded = false;
837 return capabilityCheckNeeded;