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";
63 static final String PREPARE_RELATIONSHIP_PARAM = "tmp.preparerel";
64 static final String CONFIG_FILE_ID_PARAM = "tmp.configfilesmax.configfileid";
65 static final String FILE_CATEGORY_PARAM = "file-category";
67 static final String SDC_IND = "N";
69 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
70 private final DGGeneralDBService db;
73 * Constructor which provide default DB service
75 public ConfigResourceNode() {
76 db = DGGeneralDBService.initialise();
80 * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
82 public ConfigResourceNode(DGGeneralDBService dbService) {
86 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
88 log.info("Received getConfigFiles call with params : " + inParams);
89 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
92 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
93 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
95 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
96 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
98 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
100 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
101 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
103 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
105 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
106 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
108 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
110 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
111 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
113 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
114 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
115 log.info("GetConfigFileReference Successful ");
116 } catch (Exception e) {
117 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
118 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
119 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
120 log.error("Failed in GetConfigFileReference " + e.getMessage());
122 throw new SvcLogicException(e.getMessage());
126 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
128 log.info("Received getDeviceInfo call with params : " + inParams);
129 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
132 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
133 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, DEVICE_PROTOCOL_PREFIX);
135 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
136 throw new Exception("Unable to Read device_interface_protocol");
138 status = db.getConfigureActionDGByVnfTypeNAction(ctx, CONF_ACTION_PREFIX);
139 if (status == QueryStatus.FAILURE)
140 throw new Exception("Unable to Read configure_action_dg");
142 if (status == QueryStatus.NOT_FOUND) {
143 status = db.getConfigureActionDGByVnfType(ctx, CONF_ACTION_PREFIX);
145 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
146 throw new Exception("Unable to Read configure_action_dg");
149 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
150 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
151 log.info("getCommonConfigInfo Successful ");
152 } catch (Exception e) {
153 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
154 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
155 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
156 log.error("Failed in getCommonConfigInfo " + e.getMessage());
158 throw new SvcLogicException(e.getMessage());
163 * FileCategory can be config_template, parameter_definitions, parameter_yang
165 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
167 log.info("Received getTemplate call with params : " + inParams);
169 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
170 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
171 String templateName = ctx.getAttribute("template-name");
172 QueryStatus status = null;
173 String responsePrefix1 = "";
177 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
178 log.info("RESPONSEPREFIX : " + responsePrefix);
179 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
181 if (StringUtils.isBlank(templateName)) {
183 // if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
185 status = db.getTemplate(ctx, responsePrefix, fileCategory);
186 if (status == QueryStatus.FAILURE)
187 throw new Exception("Unable to Read " + fileCategory);
190 if (status == QueryStatus.NOT_FOUND) {
193 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
195 if (status == QueryStatus.FAILURE)
196 throw new Exception("Unable to Read " + fileCategory);
198 if (status == QueryStatus.NOT_FOUND) {
200 // status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
202 // if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
203 throw new Exception("Unable to Read " + fileCategory);
208 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
210 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
211 throw new Exception("Unable to Read " + fileCategory + " template");
214 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
215 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
216 log.info("GetTemplate Successful ");
217 } catch (Exception e) {
218 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
219 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
220 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
221 log.error("Failed in getTemplate " + e.getMessage());
223 throw new SvcLogicException(e.getMessage());
227 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
229 log.info("Received saveConfigFiles call with params : " + inParams);
231 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
235 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
236 QueryStatus status = db.saveConfigFiles(ctx, CONFIG_FILES_PREFIX);
238 if (status == QueryStatus.FAILURE)
239 throw new Exception("Unable to Save " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " in configfiles");
241 status = db.getMaxConfigFileId(ctx, MAX_CONF_FILE_PREFIX, ctx.getAttribute(FILE_CATEGORY_PARAM));
243 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
244 throw new Exception("Unable to get " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " from configfiles");
246 status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
247 ctx.getAttribute(CONFIG_FILE_ID_PARAM), SDC_IND);
248 if (status == QueryStatus.FAILURE)
249 throw new Exception("Unable to save prepare_relationship");
251 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
252 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
253 log.info("saveConfigFiles Successful ");
254 } catch (Exception e) {
255 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
256 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
257 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
258 log.error("Failed in saveConfigFiles " + e.getMessage());
260 throw new SvcLogicException(e.getMessage());
264 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
266 log.info("Received updateUploadConfig call with params : " + inParams);
268 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
272 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
274 ctx.setAttribute("tmp.escaped.devicerunningconfig",
275 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
277 QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
279 if (status == QueryStatus.FAILURE)
280 throw new Exception("Unable to Save configuration in upload_config");
282 status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
284 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
285 throw new Exception("Unable to get record from upload_config");
287 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
288 Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
289 if (status == QueryStatus.FAILURE)
290 throw new Exception("Unable to upload upload_config");
292 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
293 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
294 log.info("updateUploadConfig Successful ");
295 } catch (Exception e) {
296 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
297 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
298 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
299 log.error("Failed in updateUploadConfig " + e.getMessage());
301 throw new SvcLogicException(e.getMessage());
305 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
307 log.info("Received savePrepareRelationship call with params : " + inParams);
309 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
310 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
311 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
314 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
316 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM, fileId, sdcArtifactInd);
317 if (status == QueryStatus.FAILURE)
318 throw new Exception("Unable to save prepare_relationship");
320 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
321 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
322 log.info("savePrepareRelationship Successful ");
323 } catch (Exception e) {
324 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
325 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
326 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
327 log.error("Failed in saveConfigFiles " + e.getMessage());
329 throw new SvcLogicException(e.getMessage());
333 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
335 log.info("Received saveConfigBlock call with params : " + inParams);
337 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
340 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
341 ctx.setAttribute("tmp.convertconfig.escapeData", EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
343 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
344 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
345 ctx.getAttribute("configuration"));
348 saveConfigurationBlock(inParams, ctx);
350 ctx.setAttribute("tmp.convertconfig.escapeData",
351 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
352 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
353 ctx.getAttribute("tmp.merge.mergedData"));
355 saveConfigurationData(inParams, ctx);
358 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
359 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
360 log.info("saveConfigBlock Successful ");
361 } catch (Exception e) {
362 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
363 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
364 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
365 log.error("Failed in saveConfigBlock " + e.getMessage());
367 throw new SvcLogicException(e.getMessage());
371 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
373 log.info("Received saveTemplateConfig call with params : " + inParams);
375 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
378 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
380 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
382 ctx.setAttribute("tmp.convertconfig.escapeData",
383 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
384 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
385 ctx.getAttribute("config-template.file-content"));
388 saveConfigurationData(inParams, ctx);
390 ctx.setAttribute("tmp.convertconfig.escapeData",
391 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
392 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
393 ctx.getAttribute("tmp.merge.mergedData"));
397 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
398 ctx.getAttribute("config-template.config-file-id"), "Y");
399 if (status == QueryStatus.FAILURE)
400 throw new Exception("Unable to save prepare_relationship");
402 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
403 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
404 log.info("saveTemplateConfig Successful ");
405 } catch (Exception e) {
406 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
407 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
408 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
409 log.error("Failed in saveTemplateConfig " + e.getMessage());
411 throw new SvcLogicException(e.getMessage());
415 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
417 log.info("Received saveStyleSheet call with params : " + inParams);
419 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
423 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
424 ctx.setAttribute("tmp.convertconfig.escapeData",
425 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
426 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
427 ctx.getAttribute("tmp.merge.mergedData"));
429 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
430 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
431 log.info("saveStyleSheet Successful ");
432 } catch (Exception e) {
433 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
434 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
435 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
436 log.error("Failed in saveStyleSheet " + e.getMessage());
438 throw new SvcLogicException(e.getMessage());
442 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
444 log.info("Received saveStyleSheet call with params : " + inParams);
446 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
447 String siteLocation = ctx.getAttribute("site-location");
449 QueryStatus status = null;
453 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
455 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
457 if (status == QueryStatus.FAILURE)
458 throw new Exception("Unable to Read smm file");
460 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
462 if (status == QueryStatus.FAILURE)
463 throw new Exception("Unable to Read intermediate_ca_chain file");
465 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
468 if (status == QueryStatus.FAILURE)
469 throw new Exception("Unable to Read server_certificate_and_key file");
471 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
472 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
473 log.info("saveStyleSheet Successful ");
474 } catch (Exception e) {
475 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
476 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
477 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
478 log.error("Failed in saveStyleSheet " + e.getMessage());
480 throw new SvcLogicException(e.getMessage());
484 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
485 String fileContent, String deviceConfig) throws SvcLogicException {
486 ctx.setAttribute("data-source", dataSource);
487 ctx.setAttribute("file-content", fileContent);
488 ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
489 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
491 saveConfigFiles(inParams, ctx);
494 public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
495 ctx.setAttribute("data-source", "Request");
496 ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
497 ctx.setAttribute(FILE_CATEGORY_PARAM, "configuration_block");
498 saveConfigFiles(inParams, ctx);
501 public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
502 ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
503 ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
504 ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
505 saveConfigFiles(inParams, ctx);
508 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
509 throws SvcLogicException {
511 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
513 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
514 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
515 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
516 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
518 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
520 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
521 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
523 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
524 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
525 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
526 log.info("getConfigFilesByVnfVmNCategory Successful "
527 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
528 } catch (Exception e) {
529 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
530 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
531 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
532 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
534 throw new SvcLogicException(e.getMessage());
538 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
539 throws SvcLogicException {
541 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
543 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
545 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
547 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
548 throw new Exception("Unable to get download config template.");
550 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
551 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
552 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
553 log.info("getDownloadConfigTemplateByVnf 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 getDownloadConfigTemplateByVnf " + e.getMessage());
561 throw new SvcLogicException(e.getMessage());
565 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
567 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
569 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
570 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
574 SvcLogicContext logctx = new SvcLogicContext();
575 String escapedMessage = EscapeUtils.escapeSql(message);
577 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
578 logctx.setAttribute("log-message-type", messageType);
579 logctx.setAttribute("log-message", escapedMessage);
581 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
582 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
584 logctx.setAttribute("log-message", null);
586 if (status == QueryStatus.FAILURE)
587 throw new Exception("Unable to insert into config_transaction_log");
589 } catch (Exception e) {
590 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
591 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
592 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
594 throw new SvcLogicException(e.getMessage());
598 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
600 log.info("Received getVnfcReference call with params : " + inParams);
602 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
603 QueryStatus status = null;
606 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
607 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
609 if (status == QueryStatus.FAILURE)
610 throw new Exception("Unable to Read vnfc-reference");
612 // else if (status == QueryStatus.NOT_FOUND ) {
613 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
615 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
616 throw new Exception("Unable to Read vnfc reference");
620 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
621 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
622 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
623 log.info("getVnfcReference Successful ");
624 } catch (Exception e) {
625 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
626 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
627 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
628 log.error("Failed in getVnfcReference " + e.getMessage());
630 throw new SvcLogicException(e.getMessage());
634 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
635 log.info("Received getCapability call with params : " + inParams);
636 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
637 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
638 String caplevel = inParams.get("caplevel");
639 String findCapability = inParams.get("checkCapability");
640 String vServerId = inParams.get("vServerId");
641 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
642 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
643 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
644 log.info("getCapability Successful - No need for capability check for this action");
648 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
649 log.info("getCapability::returned from DB::+cap");
650 if (StringUtils.isBlank(cap)) {
651 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
652 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
653 log.info("getCapability Successful - No capability blocks found");
656 ObjectMapper mapper = new ObjectMapper();
657 JsonNode caps = mapper.readTree(cap);
658 log.info("From DB = " + caps);
659 JsonNode capabilities = caps.get("capabilities");
660 log.info("capabilities = " + capabilities);
661 if (caplevel != null && !caplevel.isEmpty()) {
662 JsonNode subCapabilities = capabilities.get(caplevel);
663 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
664 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
665 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
666 ctx.setAttribute("capabilities", "None");
667 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
668 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
669 log.info("getCapability Successful ");
672 if (findCapability != null && !findCapability.isEmpty()) {
673 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
674 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL))
675 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
677 ctx.setAttribute("capabilities", "Supported");
679 ctx.setAttribute("capabilities", "Not-Supported");
682 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
686 ctx.setAttribute(responsePrefix + "capabilities", capabilities.toString());
687 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
688 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
689 log.info("getCapability Successful ");
690 } catch (Exception e) {
691 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
692 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
693 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
694 log.error("Failed in getCapability " + e.getMessage());
696 throw new SvcLogicException(e.getMessage());
700 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
701 JsonNode subCapabilities) throws Exception {
702 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
704 if (subCapabilities.size() == 0) {
705 ctx.setAttribute("capabilities", "None");
706 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
709 JsonNode vmCaps = null;
710 for (JsonNode cap : subCapabilities) {
711 if (null != cap && null != cap.get(findCapability)
712 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
713 vmCaps = cap.get(findCapability);
714 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
719 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
720 ctx.setAttribute("capabilities", "Not-Supported");
721 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
725 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
726 if (StringUtils.isBlank(vnfcFunctionCode)) {
727 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
728 ctx.setAttribute("capabilities", "Not-Supported");
732 if (vmCaps.toString().contains(vnfcFunctionCode))
733 ctx.setAttribute("capabilities", "Supported");
735 ctx.setAttribute("capabilities", "Not-Supported");
736 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute("capabilities"));
739 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) throws Exception {
740 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
741 for (Object key : ctx.getAttributeKeySet()) {
742 String parmName = (String) key;
743 String parmValue = ctx.getAttribute(parmName);
744 log.info(parmName + "=" + parmValue);
747 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
748 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
749 return vnfcFunctionCode;
752 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
753 boolean capabilityCheckNeeded = true;
754 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
755 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<AppcDataServiceConstant.ACTIONS>(
756 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
757 for (AppcDataServiceConstant.ACTIONS action : actionList) {
758 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
759 capabilityCheckNeeded = false;
764 return capabilityCheckNeeded;