2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.data.services.node;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.databind.JsonNode;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.List;
34 import org.apache.commons.lang3.StringUtils;
35 import org.onap.appc.data.services.AppcDataServiceConstant;
36 import org.onap.appc.data.services.db.DGGeneralDBService;
37 import org.onap.appc.data.services.utils.EscapeUtils;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
43 public class ConfigResourceNode implements SvcLogicJavaPlugin {
45 static final String DEVICE_CONF_PREFIX = "configfilereference-deviceconfig";
46 static final String DEVICE_CONF_FILE_TYPE = "device_configuration";
48 static final String SUCCESS_PREFIX = "configfilereference-success";
49 static final String SUCCESS_FILE_TYPE = "configuration_success";
51 static final String FAILURE_PREFIX = "configfilereference-failure";
52 static final String FAILURE_FILE_TYPE = "configuration_error";
54 static final String LOG_PREFIX = "configfilereference-log";
55 static final String LOG_FILE_TYPE = "log";
57 static final String DEVICE_PROTOCOL_PREFIX = "tmp.deviceinterfaceprotocol";
58 static final String CONF_ACTION_PREFIX = "tmp.configureactiondg";
60 static final String CONFIG_FILES_PREFIX = "tmp.configFiles";
61 static final String MAX_CONF_FILE_PREFIX = "tmp.configfilesmax";
62 static final String UPLOAD_CONFIG_PREFIX = "tmp.uploadConfig";
63 static final String UPLOAD_CONFIG_INFO_PREFIX = "tmp.uploadConfigInfo";
65 static final String PREPARE_RELATIONSHIP_PARAM = "tmp.preparerel";
66 static final String CONFIG_FILE_ID_PARAM = "tmp.configfilesmax.configfileid";
67 static final String FILE_CATEGORY_PARAM = "file-category";
68 static final String UPLOAD_CONFIG_ID_PARAM = "tmp.uploadConfigInfo.UPLOAD-CONFIG-ID";
70 static final String SDC_IND = "N";
71 static final String TMP_CONVERTCONFIG_ESC_DATA = "tmp.convertconfig.escapeData";
72 static final String CONFIG_PARAMS = "configuration-params";
73 static final String TMP_MERGE_MERGED_DATA = "tmp.merge.mergedData";
74 static final String DATA_SOURCE = "data-source";
75 static final String FILE_CONTENT = "file-content";
76 static final String CAPABILITIES = "capabilities";
77 static final String NOT_SUPPORTED = "Not-Supported";
78 static final String UNABLE_TO_READ_STR = "Unable to Read ";
79 static final String UNABLE_TO_SAVE_RELATIONSHIP_STR = "Unable to save prepare_relationship";
82 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");
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 status = db.getTemplate(ctx, responsePrefix, fileCategory);
204 if (status == QueryStatus.FAILURE) {
205 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
208 if (status == QueryStatus.NOT_FOUND) {
210 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
212 if (status == QueryStatus.FAILURE) {
213 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
216 if (status == QueryStatus.NOT_FOUND) {
217 throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
222 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
224 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
225 throw new QueryException(UNABLE_TO_READ_STR + fileCategory + " template");
229 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
230 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
231 log.info("GetTemplate Successful ");
232 } catch (Exception e) {
233 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
234 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
235 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
236 log.error("Failed in getTemplate", e);
238 throw new SvcLogicException(e.getMessage());
242 void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
244 log.info("Received saveConfigFiles call with params : " + inParams);
246 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
250 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
251 QueryStatus status = db.saveConfigFiles(ctx, CONFIG_FILES_PREFIX);
253 if (status == QueryStatus.FAILURE) {
254 throw new QueryException("Unable to Save " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " in configfiles");
257 status = db.getMaxConfigFileId(ctx, MAX_CONF_FILE_PREFIX, ctx.getAttribute(FILE_CATEGORY_PARAM));
259 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
260 throw new QueryException(
261 "Unable to get " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " from configfiles");
264 status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
265 ctx.getAttribute(CONFIG_FILE_ID_PARAM), SDC_IND);
266 if (status == QueryStatus.FAILURE) {
267 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
270 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
271 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
272 log.info("saveConfigFiles Successful ");
273 } catch (Exception e) {
274 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
275 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
276 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
277 log.error("Failed in saveConfigFiles", e);
279 throw new SvcLogicException(e.getMessage());
283 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
285 log.info("Received updateUploadConfig call with params : " + inParams);
287 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
291 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
293 ctx.setAttribute("tmp.escaped.devicerunningconfig",
294 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
296 QueryStatus status = db.saveUploadConfig(ctx, UPLOAD_CONFIG_PREFIX);
298 if (status == QueryStatus.FAILURE) {
299 throw new QueryException("Unable to Save configuration in upload_config");
302 status = db.getUploadConfigInfo(ctx, UPLOAD_CONFIG_INFO_PREFIX);
304 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
305 throw new QueryException("Unable to get record from upload_config");
308 status = db.updateUploadConfig(ctx, UPLOAD_CONFIG_PREFIX,
309 Integer.parseInt(ctx.getAttribute(UPLOAD_CONFIG_ID_PARAM)));
310 if (status == QueryStatus.FAILURE)
311 throw new QueryException("Unable to upload upload_config");
313 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
314 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
315 log.info("updateUploadConfig Successful ");
316 } catch (Exception e) {
317 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
318 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
319 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
320 log.error("Failed in updateUploadConfig", e);
322 throw new SvcLogicException(e.getMessage());
326 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
328 log.info("Received savePrepareRelationship call with params : " + inParams);
330 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
331 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
332 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
335 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
337 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM, fileId, sdcArtifactInd);
338 if (status == QueryStatus.FAILURE) {
339 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
342 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
343 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
344 log.info("savePrepareRelationship 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 saveConfigFiles", e);
351 throw new SvcLogicException(e.getMessage());
355 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
357 log.info("Received saveConfigBlock call with params : " + inParams);
359 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
362 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
363 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA, EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
365 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
366 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
367 ctx.getAttribute("configuration"));
370 saveConfigurationBlock(inParams, ctx);
372 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
373 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
374 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
375 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
377 saveConfigurationData(inParams, ctx);
380 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
381 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
382 log.info("saveConfigBlock Successful ");
383 } catch (Exception e) {
384 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
385 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
386 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
387 log.error("Failed in saveConfigBlock", e);
389 throw new SvcLogicException(e.getMessage());
393 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
395 log.info("Received saveTemplateConfig call with params : " + inParams);
397 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
400 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
402 if (StringUtils.isBlank(ctx.getAttribute(CONFIG_PARAMS))) {
404 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
405 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
406 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
407 ctx.getAttribute("config-template.file-content"));
410 saveConfigurationData(inParams, ctx);
412 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
413 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
414 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
415 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
419 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
420 ctx.getAttribute("config-template.config-file-id"), "Y");
421 if (status == QueryStatus.FAILURE) {
422 throw new QueryException(UNABLE_TO_SAVE_RELATIONSHIP_STR);
425 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
426 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
427 log.info("saveTemplateConfig Successful ");
428 } catch (Exception e) {
429 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
430 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
431 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
432 log.error("Failed in saveTemplateConfig", e);
434 throw new SvcLogicException(e.getMessage());
438 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
440 log.info("Received saveStyleSheet call with params : " + inParams);
442 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
446 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
447 ctx.setAttribute(TMP_CONVERTCONFIG_ESC_DATA,
448 EscapeUtils.escapeSql(ctx.getAttribute(TMP_MERGE_MERGED_DATA)));
449 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA),
450 ctx.getAttribute(TMP_MERGE_MERGED_DATA));
452 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
453 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
454 log.info("saveStyleSheet Successful ");
455 } catch (Exception e) {
456 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
457 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
458 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
459 log.error("Failed in saveStyleSheet", e);
461 throw new SvcLogicException(e.getMessage());
465 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
467 log.info("Received saveStyleSheet call with params : " + inParams);
469 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
470 String siteLocation = ctx.getAttribute(SITE_LOCATION_PARAM);
476 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
478 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
480 if (status == QueryStatus.FAILURE) {
481 throw new QueryException("Unable to Read smm file");
484 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
486 if (status == QueryStatus.FAILURE) {
487 throw new QueryException("Unable to Read intermediate_ca_chain file");
490 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
493 if (status == QueryStatus.FAILURE) {
494 throw new QueryException("Unable to Read server_certificate_and_key file");
497 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
498 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
499 log.info("saveStyleSheet Successful ");
500 } catch (Exception e) {
501 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
502 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
503 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
504 log.error("Failed in saveStyleSheet", e);
506 throw new SvcLogicException(e.getMessage());
510 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
511 String fileContent, String deviceConfig) throws SvcLogicException {
512 ctx.setAttribute(DATA_SOURCE, dataSource);
513 ctx.setAttribute(FILE_CONTENT, fileContent);
514 ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
515 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
517 saveConfigFiles(inParams, ctx);
520 private void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
521 ctx.setAttribute(DATA_SOURCE, "Request");
522 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(TMP_CONVERTCONFIG_ESC_DATA));
523 ctx.setAttribute(FILE_CATEGORY_PARAM, "configuration_block");
524 saveConfigFiles(inParams, ctx);
527 private void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
528 ctx.setAttribute(DATA_SOURCE, ctx.getAttribute("originator-id"));
529 ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(CONFIG_PARAMS));
530 ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
531 saveConfigFiles(inParams, ctx);
534 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
535 throws SvcLogicException {
537 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
539 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
540 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
541 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
542 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
544 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
546 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
547 throw new QueryException("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
550 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
551 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
552 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
553 log.info("getConfigFilesByVnfVmNCategory Successful "
554 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
555 } catch (Exception e) {
556 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
557 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
558 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
559 log.error("Failed in getConfigFilesByVnfVmNCategory", e);
561 throw new SvcLogicException(e.getMessage());
565 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
566 throws SvcLogicException {
568 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
570 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
572 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
574 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
575 throw new QueryException("Unable to get download config template.");
578 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
579 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
580 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
581 log.info("getDownloadConfigTemplateByVnf Successful "
582 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
583 } catch (Exception e) {
584 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
585 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
586 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
587 log.error("Failed in getDownloadConfigTemplateByVnf", e);
589 throw new SvcLogicException(e.getMessage());
593 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
595 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
597 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
598 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
602 SvcLogicContext logctx = new SvcLogicContext();
603 String escapedMessage = EscapeUtils.escapeSql(message);
605 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
606 logctx.setAttribute("log-message-type", messageType);
607 logctx.setAttribute("log-message", escapedMessage);
609 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
610 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
612 logctx.setAttribute("log-message", null);
614 if (status == QueryStatus.FAILURE) {
615 throw new QueryException("Unable to insert into config_transaction_log");
618 } catch (Exception e) {
619 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
620 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
621 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
622 log.error("Failed in saveConfigTransactionLog", e);
623 throw new SvcLogicException(e.getMessage());
627 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
629 log.info("Received getVnfcReference call with params : " + inParams);
631 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
635 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
636 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
638 if (status == QueryStatus.FAILURE) {
639 throw new QueryException("Unable to Read vnfc-reference");
642 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
644 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
645 throw new QueryException("Unable to Read vnfc reference");
648 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
649 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
650 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
651 log.info("getVnfcReference Successful ");
652 } catch (Exception e) {
653 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
654 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
655 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
656 log.error("Failed in getVnfcReference", e);
658 throw new SvcLogicException(e.getMessage());
662 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
663 log.info("Received getCapability call with params : " + inParams);
664 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
665 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
666 String caplevel = inParams.get("caplevel");
667 String findCapability = inParams.get("checkCapability");
668 String vServerId = inParams.get("vServerId");
669 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
670 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
671 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
672 log.info("getCapability Successful - No need for capability check for this action");
676 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
677 log.info("getCapability::returned from DB::+cap");
678 if (StringUtils.isBlank(cap)) {
679 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
680 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
681 log.info("getCapability Successful - No capability blocks found");
684 ObjectMapper mapper = new ObjectMapper();
685 JsonNode caps = mapper.readTree(cap);
686 log.info("From DB = " + caps);
687 JsonNode capabilities = caps.get(CAPABILITIES);
688 log.info("capabilities = " + capabilities);
689 if (caplevel != null && !caplevel.isEmpty()) {
690 JsonNode subCapabilities = capabilities.get(caplevel);
691 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
692 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
693 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
694 ctx.setAttribute(CAPABILITIES, "None");
695 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
696 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
697 log.info("getCapability Successful ");
700 if (findCapability != null && !findCapability.isEmpty()) {
701 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
702 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
703 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
705 ctx.setAttribute(CAPABILITIES, "Supported");
708 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
711 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
715 ctx.setAttribute(responsePrefix + CAPABILITIES, capabilities.toString());
717 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
718 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
719 log.info("getCapability Successful ");
720 } catch (Exception e) {
721 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
722 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
723 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
724 log.error("Failed in getCapability", e);
726 throw new SvcLogicException(e.getMessage());
730 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
731 JsonNode subCapabilities) {
732 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
734 if (subCapabilities.size() == 0) {
735 ctx.setAttribute(CAPABILITIES, "None");
736 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
739 JsonNode vmCaps = null;
740 for (JsonNode cap : subCapabilities) {
741 if (null != cap && null != cap.get(findCapability)
742 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
743 vmCaps = cap.get(findCapability);
744 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
749 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
750 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
751 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
755 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
756 if (StringUtils.isBlank(vnfcFunctionCode)) {
757 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
758 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
762 if (vmCaps.toString().contains(vnfcFunctionCode)) {
763 ctx.setAttribute(CAPABILITIES, "Supported");
765 ctx.setAttribute(CAPABILITIES, NOT_SUPPORTED);
767 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute(CAPABILITIES));
770 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) {
771 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
772 for (Object key : ctx.getAttributeKeySet()) {
773 String parmName = (String) key;
774 String parmValue = ctx.getAttribute(parmName);
775 log.info(parmName + "=" + parmValue);
778 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
779 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
780 return vnfcFunctionCode;
783 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
784 boolean capabilityCheckNeeded = true;
785 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
786 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<>(
787 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
788 for (AppcDataServiceConstant.ACTIONS action : actionList) {
789 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
790 capabilityCheckNeeded = false;
795 return capabilityCheckNeeded;