2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
25 package org.onap.appc.data.services.node;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import com.fasterxml.jackson.databind.JsonNode;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.List;
35 import org.apache.commons.lang3.StringUtils;
36 import org.onap.appc.data.services.AppcDataServiceConstant;
37 import org.onap.appc.data.services.db.DGGeneralDBService;
38 import org.onap.appc.data.services.utils.EscapeUtils;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
44 public class ConfigResourceNode implements SvcLogicJavaPlugin {
46 static final String DEVICE_CONF_PREFIX = "configfilereference-deviceconfig";
47 static final String DEVICE_CONF_FILE_TYPE = "device_configuration";
49 static final String SUCCESS_PREFIX = "configfilereference-success";
50 static final String SUCCESS_FILE_TYPE = "configuration_success";
52 static final String FAILURE_PREFIX = "configfilereference-failure";
53 static final String FAILURE_FILE_TYPE = "configuration_error";
55 static final String LOG_PREFIX = "configfilereference-log";
56 static final String LOG_FILE_TYPE = "log";
58 static final String DEVICE_PROTOCOL_PREFIX = "tmp.deviceinterfaceprotocol";
59 static final String CONF_ACTION_PREFIX = "tmp.configureactiondg";
61 static final String CONFIG_FILES_PREFIX = "tmp.configFiles";
62 static final String MAX_CONF_FILE_PREFIX = "tmp.configfilesmax";
63 static final String UPLOAD_CONFIG_PREFIX = "tmp.uploadConfig";
64 static final String UPLOAD_CONFIG_INFO_PREFIX = "tmp.uploadConfigInfo";
66 static final String PREPARE_RELATIONSHIP_PARAM = "tmp.preparerel";
67 static final String CONFIG_FILE_ID_PARAM = "tmp.configfilesmax.configfileid";
68 static final String FILE_CATEGORY_PARAM = "file-category";
69 static final String UPLOAD_CONFIG_ID_PARAM = "tmp.uploadConfigInfo.UPLOAD-CONFIG-ID";
71 static final String SDC_IND = "N";
72 static final String TMP_CONVERTCONFIG_ESC_DATA = "tmp.convertconfig.escapeData";
73 static final String CONFIG_PARAMS = "configuration-params";
74 static final String TMP_MERGE_MERGED_DATA = "tmp.merge.mergedData";
75 static final String DATA_SOURCE = "data-source";
76 static final String FILE_CONTENT = "file-content";
77 static final String CAPABILITIES = "capabilities";
78 static final String NOT_SUPPORTED = "Not-Supported";
79 static final String UNABLE_TO_READ_STR = "Unable to Read ";
80 static final String UNABLE_TO_SAVE_RELATIONSHIP_STR = "Unable to save prepare_relationship";
83 static final String SITE_LOCATION_PARAM = "site-location";
85 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
86 private final DGGeneralDBService db;
89 * Constructor which provide default DB service
91 public ConfigResourceNode() {
92 db = DGGeneralDBService.initialise();
96 * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
98 public ConfigResourceNode(DGGeneralDBService dbService) {
102 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
104 log.info("Received getConfigFiles call with params : " + inParams);
105 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
108 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
109 QueryStatus status = db
110 .getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
112 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
113 throw new QueryException("Unable to Read ConfigFileReference:device-configuration");
116 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
118 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
119 throw new QueryException("Unable to Read ConfigFileReference:configuration_success");
122 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
124 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
125 throw new QueryException("Unable to Read ConfigFileReference:configuration_error");
128 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
130 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
131 throw new QueryException("Unable to Read ConfigFileReference:configuration_log");
134 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
135 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
136 log.info("GetConfigFileReference Successful ");
137 } catch (Exception e) {
138 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
139 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
140 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
141 log.error("Failed in GetConfigFileReference", e);
142 throw new SvcLogicException(e.getMessage());
146 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
148 log.info("Received getDeviceInfo call with params : " + inParams);
149 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
152 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
153 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, DEVICE_PROTOCOL_PREFIX);
155 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
156 throw new QueryException("Unable to Read device_interface_protocol");
159 status = db.getConfigureActionDGByVnfTypeNAction(ctx, CONF_ACTION_PREFIX);
160 if (status == QueryStatus.FAILURE) {
161 throw new QueryException("Unable to Read configure_action_dg");
164 if (status == QueryStatus.NOT_FOUND) {
165 status = db.getConfigureActionDGByVnfType(ctx, CONF_ACTION_PREFIX);
167 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
168 throw new QueryException("Unable to Read configure_action_dg");
172 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
173 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
174 log.info("getCommonConfigInfo Successful ");
175 } catch (Exception e) {
176 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
177 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
178 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
179 log.error("Failed in getCommonConfigInfo", e);
180 throw new SvcLogicException(e.getMessage());
185 * FileCategory can be config_template, parameter_definitions, parameter_yang
187 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
189 log.info("Received getTemplate call with params : " + inParams);
191 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
192 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
193 String templateName = ctx.getAttribute(AppcDataServiceConstant.TEMPLATE_NAME);
194 String templateModelId = ctx.getAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID);
196 String responsePrefix1 = "";
200 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
201 log.info("RESPONSEPREFIX : " + responsePrefix);
202 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
204 if (StringUtils.isBlank(templateName)) {
205 if (StringUtils.isNotBlank(templateModelId)) {
206 status = db.getTemplateWithTemplateModelId(ctx, responsePrefix, fileCategory, templateModelId);
207 if (status == QueryStatus.FAILURE) {
208 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
210 if (!(status == QueryStatus.NOT_FOUND) ) {
211 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
212 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
213 log.info("GetTemplate Successful ");
217 status = db.getTemplate(ctx, responsePrefix, fileCategory);
218 if (status == QueryStatus.FAILURE) {
219 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
222 if (status == QueryStatus.NOT_FOUND) {
223 if (StringUtils.isNotBlank(templateModelId)) {
224 status = db.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, fileCategory, templateModelId);
225 if (status == QueryStatus.FAILURE) {
226 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
228 if (!(status == QueryStatus.NOT_FOUND) ) {
229 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
230 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
231 log.info("GetTemplate Successful ");
235 if (status == QueryStatus.NOT_FOUND) {
238 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
240 if (status == QueryStatus.FAILURE) {
241 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
244 if (status == QueryStatus.NOT_FOUND) {
245 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
253 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
255 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
256 throw new QueryException(UNABLE_TO_READ_STR + fileCategory + " template");
260 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
261 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
262 log.info("GetTemplate Successful ");
263 } catch (Exception e) {
264 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
265 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
266 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
267 log.error("Failed in getTemplate", e);
269 throw new SvcLogicException(e.getMessage());
273 void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
275 log.info("Received saveConfigFiles call with params : " + inParams);
277 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
281 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
282 QueryStatus status = db.saveConfigFiles(ctx, CONFIG_FILES_PREFIX);
284 if (status == QueryStatus.FAILURE) {
285 throw new QueryException("Unable to Save " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " in configfiles");
288 status = db.getMaxConfigFileId(ctx, MAX_CONF_FILE_PREFIX, ctx.getAttribute(FILE_CATEGORY_PARAM));
290 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
291 throw new QueryException(
292 "Unable to get " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " from configfiles");
295 status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
296 ctx.getAttribute(CONFIG_FILE_ID_PARAM), SDC_IND);
297 if (status == QueryStatus.FAILURE) {
298 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
301 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
302 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
303 log.info("saveConfigFiles Successful ");
304 } catch (Exception e) {
305 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
306 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
307 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
308 log.error("Failed in saveConfigFiles", e);
310 throw new SvcLogicException(e.getMessage());
314 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
316 log.info("Received updateUploadConfig call with params : " + inParams);
318 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
322 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
324 ctx.setAttribute("tmp.escaped.devicerunningconfig",
325 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
327 QueryStatus status = db.saveUploadConfig(ctx, UPLOAD_CONFIG_PREFIX);
329 if (status == QueryStatus.FAILURE) {
330 throw new QueryException("Unable to Save configuration in upload_config");
333 status = db.getUploadConfigInfo(ctx, UPLOAD_CONFIG_INFO_PREFIX);
335 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
336 throw new QueryException("Unable to get record from upload_config");
339 status = db.updateUploadConfig(ctx, UPLOAD_CONFIG_PREFIX,
340 Integer.parseInt(ctx.getAttribute(UPLOAD_CONFIG_ID_PARAM)));
341 if (status == QueryStatus.FAILURE)
342 throw new QueryException("Unable to upload upload_config");
344 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
345 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
346 log.info("updateUploadConfig Successful ");
347 } catch (Exception e) {
348 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
349 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
350 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
351 log.error("Failed in updateUploadConfig", e);
353 throw new SvcLogicException(e.getMessage());
357 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
359 log.info("Received savePrepareRelationship call with params : " + inParams);
361 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
362 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
363 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
366 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
368 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM, fileId, sdcArtifactInd);
369 if (status == QueryStatus.FAILURE) {
370 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
373 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
374 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
375 log.info("savePrepareRelationship Successful ");
376 } catch (Exception e) {
377 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
378 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
379 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
380 log.error("Failed in saveConfigFiles", e);
382 throw new SvcLogicException(e.getMessage());
386 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
388 log.info("Received saveConfigBlock call with params : " + inParams);
390 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
393 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
394 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA, EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
396 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
397 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
398 ctx.getAttribute("configuration"));
401 saveConfigurationBlock(inParams, ctx);
403 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
404 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
405 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
406 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
408 saveConfigurationData(inParams, ctx);
411 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
412 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
413 log.info("saveConfigBlock Successful ");
414 } catch (Exception e) {
415 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
416 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
417 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
418 log.error("Failed in saveConfigBlock", e);
420 throw new SvcLogicException(e.getMessage());
424 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
426 log.info("Received saveTemplateConfig call with params : " + inParams);
428 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
431 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
433 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
435 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
436 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
437 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
438 ctx.getAttribute("config-template.file-content"));
441 saveConfigurationData(inParams, ctx);
443 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
444 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
445 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
446 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
450 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
451 ctx.getAttribute("config-template.config-file-id"), "Y");
452 if (status == QueryStatus.FAILURE) {
453 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
456 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
457 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
458 log.info("saveTemplateConfig Successful ");
459 } catch (Exception e) {
460 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
461 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
462 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
463 log.error("Failed in saveTemplateConfig", e);
465 throw new SvcLogicException(e.getMessage());
469 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
471 log.info("Received saveStyleSheet call with params : " + inParams);
473 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
477 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
478 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
479 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
480 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
481 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
483 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
484 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
485 log.info("saveStyleSheet Successful ");
486 } catch (Exception e) {
487 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
488 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
489 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
490 log.error("Failed in saveStyleSheet", e);
492 throw new SvcLogicException(e.getMessage());
496 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
498 log.info("Received saveStyleSheet call with params : " + inParams);
500 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
501 String siteLocation = ctx.getAttribute(SITE_LOCATION_PARAM);
507 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
509 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
511 if (status == QueryStatus.FAILURE) {
512 throw new QueryException("Unable to Read smm file");
515 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
517 if (status == QueryStatus.FAILURE) {
518 throw new QueryException("Unable to Read intermediate_ca_chain file");
521 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
524 if (status == QueryStatus.FAILURE) {
525 throw new QueryException("Unable to Read server_certificate_and_key file");
528 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
529 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
530 log.info("saveStyleSheet Successful ");
531 } catch (Exception e) {
532 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
533 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
534 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
535 log.error("Failed in saveStyleSheet", e);
537 throw new SvcLogicException(e.getMessage());
541 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
542 String fileContent, String deviceConfig) throws SvcLogicException {
543 ctx.setAttribute(DATA_SOURCE, dataSource);
544 ctx.setAttribute(FILE_CONTENT, fileContent);
545 ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
546 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
548 saveConfigFiles(inParams, ctx);
551 private void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
552 ctx.setAttribute(DATA_SOURCE, "Request");
553 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA));
554 ctx.setAttribute(FILE_CATEGORY_PARAM, "configuration_block");
555 saveConfigFiles(inParams, ctx);
558 protected void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
559 ctx.setAttribute(DATA_SOURCE, ctx.getAttribute("originator-id"));
560 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(CONFIG_PARAMS));
561 ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
562 saveConfigFiles(inParams, ctx);
565 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
566 throws SvcLogicException {
568 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
570 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
571 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
572 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
573 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
575 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(AppcDataServiceConstant.TEMPLATE_MODEL_ID);
663 log.info("getVnfcReference():::" + templateModelId);
664 QueryStatus status = null;
667 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
669 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
670 if (status == QueryStatus.FAILURE) {
671 throw new QueryException("Unable to Read vnfc-reference");
675 if (StringUtils.isNotBlank(templateModelId)) {
676 status = db.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, templateModelId);
677 if (status == QueryStatus.FAILURE) {
678 throw new QueryException("Unable to Read vnfc-reference with " + AppcDataServiceConstant.TEMPLATE_MODEL_ID);
681 if (StringUtils.isBlank(templateModelId) || (StringUtils.isNotBlank(templateModelId) && (status == QueryStatus.NOT_FOUND))) {
682 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
684 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
685 throw new QueryException("Unable to Read vnfc reference");
689 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
690 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
691 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
692 log.info("getVnfcReference Successful ");
693 } catch (Exception e) {
694 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
695 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
696 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
697 log.error("Failed in getVnfcReference", e);
699 throw new SvcLogicException(e.getMessage());
703 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
704 log.info("Received getCapability call with params : " + inParams);
705 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
706 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
707 String caplevel = inParams.get("caplevel");
708 String findCapability = inParams.get("checkCapability");
709 String vServerId = inParams.get("vServerId");
710 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
711 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
712 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
713 log.info("getCapability Successful - No need for capability check for this action");
717 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
718 log.info("getCapability::returned from DB::+cap");
719 if (StringUtils.isBlank(cap)) {
720 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
721 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
722 log.info("getCapability Successful - No capability blocks found");
725 ObjectMapper mapper = new ObjectMapper();
726 JsonNode caps = mapper.readTree(cap);
727 log.info("From DB = " + caps);
728 JsonNode capabilities = caps.get(CAPABILITIES);
729 log.info("capabilities = " + capabilities);
730 if (caplevel != null && !caplevel.isEmpty()) {
731 JsonNode subCapabilities = capabilities.get(caplevel);
732 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
733 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
734 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
735 ctx.setAttribute(CAPABILITIES, "None");
736 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
737 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
738 log.info("getCapability Successful ");
741 if (findCapability != null && !findCapability.isEmpty()) {
742 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
743 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
744 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
746 ctx.setAttribute(CAPABILITIES, "Supported");
749 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
752 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
756 ctx.setAttribute(responsePrefix + CAPABILITIES, capabilities.toString());
758 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
759 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
760 log.info("getCapability Successful ");
761 } catch (Exception e) {
762 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
763 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
764 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
765 log.error("Failed in getCapability", e);
767 throw new SvcLogicException(e.getMessage());
771 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
772 JsonNode subCapabilities) {
773 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
775 if (subCapabilities.size() == 0) {
776 ctx.setAttribute(CAPABILITIES, "None");
777 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
780 JsonNode vmCaps = null;
781 for (JsonNode cap : subCapabilities) {
782 if (null != cap && null != cap.get(findCapability)
783 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
784 vmCaps = cap.get(findCapability);
785 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
790 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
791 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
792 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
796 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
797 if (StringUtils.isBlank(vnfcFunctionCode)) {
798 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
799 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
803 if (vmCaps.toString().contains(vnfcFunctionCode)) {
804 ctx.setAttribute(CAPABILITIES, "Supported");
806 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
808 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute(CAPABILITIES));
811 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) {
812 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
813 for (Object key : ctx.getAttributeKeySet()) {
814 String parmName = (String) key;
815 String parmValue = ctx.getAttribute(parmName);
816 log.info(parmName + "=" + parmValue);
819 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
820 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
821 return vnfcFunctionCode;
824 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
825 boolean capabilityCheckNeeded = true;
826 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
827 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<>(
828 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
829 for (AppcDataServiceConstant.ACTIONS action : actionList) {
830 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
831 capabilityCheckNeeded = false;
836 return capabilityCheckNeeded;