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 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
58 private final DGGeneralDBService db;
61 * Constructor which provide default DB service
63 public ConfigResourceNode() {
64 db = DGGeneralDBService.initialise();
68 * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
70 public ConfigResourceNode(DGGeneralDBService dbService) {
74 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
76 log.info("Received getConfigFiles call with params : " + inParams);
77 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
80 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
81 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
83 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
84 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
86 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
88 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
89 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
91 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
93 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
94 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
96 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
98 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
99 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
101 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
102 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
103 log.info("GetConfigFileReference Successful ");
104 } catch (Exception e) {
105 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
106 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
107 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
108 log.error("Failed in GetConfigFileReference " + e.getMessage());
110 throw new SvcLogicException(e.getMessage());
114 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
116 log.info("Received getDeviceInfo call with params : " + inParams);
117 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
120 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
121 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
123 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
124 throw new Exception("Unable to Read device_interface_protocol");
126 status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
127 if (status == QueryStatus.FAILURE)
128 throw new Exception("Unable to Read configure_action_dg");
130 if (status == QueryStatus.NOT_FOUND) {
131 status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");
133 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
134 throw new Exception("Unable to Read configure_action_dg");
137 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
138 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
139 log.info("getCommonConfigInfo Successful ");
140 } catch (Exception e) {
141 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
142 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
143 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
144 log.error("Failed in getCommonConfigInfo " + e.getMessage());
146 throw new SvcLogicException(e.getMessage());
151 // fileCategory Can be config_template, parameter_definitions, parameter_yang
152 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
154 log.info("Received getTemplate call with params : " + inParams);
156 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
157 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
158 String templateName = ctx.getAttribute("template-name");
159 QueryStatus status = null;
160 String responsePrefix1 = "";
164 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
165 log.info("RESPONSEPREFIX : " + responsePrefix);
166 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
168 if (StringUtils.isBlank(templateName)) {
170 // if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
172 status = db.getTemplate(ctx, responsePrefix, fileCategory);
173 if (status == QueryStatus.FAILURE)
174 throw new Exception("Unable to Read " + fileCategory);
177 if (status == QueryStatus.NOT_FOUND) {
180 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
182 if (status == QueryStatus.FAILURE)
183 throw new Exception("Unable to Read " + fileCategory);
185 if (status == QueryStatus.NOT_FOUND) {
187 // status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
189 // if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
190 throw new Exception("Unable to Read " + fileCategory);
195 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
197 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
198 throw new Exception("Unable to Read " + fileCategory + " template");
201 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
202 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
203 log.info("GetTemplate Successful ");
204 } catch (Exception e) {
205 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
206 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
207 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
208 log.error("Failed in getTemplate " + e.getMessage());
210 throw new SvcLogicException(e.getMessage());
214 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
216 log.info("Received saveConfigFiles call with params : " + inParams);
218 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
222 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
223 QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
225 if (status == QueryStatus.FAILURE)
226 throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
228 status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
230 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
231 throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
233 status = db.savePrepareRelationship(ctx, "tmp.preparerel",
234 ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
235 if (status == QueryStatus.FAILURE)
236 throw new Exception("Unable to save prepare_relationship");
238 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
239 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
240 log.info("saveConfigFiles Successful ");
241 } catch (Exception e) {
242 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
243 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
244 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
245 log.error("Failed in saveConfigFiles " + e.getMessage());
247 throw new SvcLogicException(e.getMessage());
251 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
253 log.info("Received updateUploadConfig call with params : " + inParams);
255 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
259 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
261 ctx.setAttribute("tmp.escaped.devicerunningconfig",
262 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
264 QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
266 if (status == QueryStatus.FAILURE)
267 throw new Exception("Unable to Save configuration in upload_config");
269 status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
271 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
272 throw new Exception("Unable to get record from upload_config");
274 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
275 Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
276 if (status == QueryStatus.FAILURE)
277 throw new Exception("Unable to upload upload_config");
279 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
280 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
281 log.info("updateUploadConfig Successful ");
282 } catch (Exception e) {
283 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
284 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
285 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
286 log.error("Failed in updateUploadConfig " + e.getMessage());
288 throw new SvcLogicException(e.getMessage());
292 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
294 log.info("Received savePrepareRelationship call with params : " + inParams);
296 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
297 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
298 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
301 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
303 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
304 if (status == QueryStatus.FAILURE)
305 throw new Exception("Unable to save prepare_relationship");
307 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
308 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
309 log.info("savePrepareRelationship Successful ");
310 } catch (Exception e) {
311 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
312 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
313 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
314 log.error("Failed in saveConfigFiles " + e.getMessage());
316 throw new SvcLogicException(e.getMessage());
320 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
322 log.info("Received saveConfigBlock call with params : " + inParams);
324 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
327 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
328 ctx.setAttribute("tmp.convertconfig.escapeData", EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
330 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
331 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
332 ctx.getAttribute("configuration"));
335 saveConfigurationBlock(inParams, ctx);
337 ctx.setAttribute("tmp.convertconfig.escapeData",
338 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
339 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
340 ctx.getAttribute("tmp.merge.mergedData"));
342 saveConfigurationData(inParams, ctx);
345 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
346 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
347 log.info("saveConfigBlock Successful ");
348 } catch (Exception e) {
349 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
350 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
351 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
352 log.error("Failed in saveConfigBlock " + e.getMessage());
354 throw new SvcLogicException(e.getMessage());
358 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
360 log.info("Received saveTemplateConfig call with params : " + inParams);
362 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
365 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
367 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
369 ctx.setAttribute("tmp.convertconfig.escapeData",
370 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
371 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
372 ctx.getAttribute("config-template.file-content"));
375 saveConfigurationData(inParams, ctx);
377 ctx.setAttribute("tmp.convertconfig.escapeData",
378 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
379 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
380 ctx.getAttribute("tmp.merge.mergedData"));
384 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
385 ctx.getAttribute("config-template.config-file-id"), "Y");
386 if (status == QueryStatus.FAILURE)
387 throw new Exception("Unable to save prepare_relationship");
389 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
390 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
391 log.info("saveTemplateConfig Successful ");
392 } catch (Exception e) {
393 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
394 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
395 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
396 log.error("Failed in saveTemplateConfig " + e.getMessage());
398 throw new SvcLogicException(e.getMessage());
402 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
404 log.info("Received saveStyleSheet call with params : " + inParams);
406 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
410 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
411 ctx.setAttribute("tmp.convertconfig.escapeData",
412 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
413 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
414 ctx.getAttribute("tmp.merge.mergedData"));
416 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
417 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
418 log.info("saveStyleSheet Successful ");
419 } catch (Exception e) {
420 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
421 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
422 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
423 log.error("Failed in saveStyleSheet " + e.getMessage());
425 throw new SvcLogicException(e.getMessage());
429 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
431 log.info("Received saveStyleSheet call with params : " + inParams);
433 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
434 String siteLocation = ctx.getAttribute("site-location");
436 QueryStatus status = null;
440 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
442 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
444 if (status == QueryStatus.FAILURE)
445 throw new Exception("Unable to Read smm file");
447 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
449 if (status == QueryStatus.FAILURE)
450 throw new Exception("Unable to Read intermediate_ca_chain file");
452 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
455 if (status == QueryStatus.FAILURE)
456 throw new Exception("Unable to Read server_certificate_and_key file");
458 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
459 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
460 log.info("saveStyleSheet Successful ");
461 } catch (Exception e) {
462 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
463 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
464 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
465 log.error("Failed in saveStyleSheet " + e.getMessage());
467 throw new SvcLogicException(e.getMessage());
471 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
472 String fileContent, String deviceConfig) throws SvcLogicException {
473 ctx.setAttribute("data-source", dataSource);
474 ctx.setAttribute("file-content", fileContent);
475 ctx.setAttribute("file-category", "device_configuration");
476 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
478 saveConfigFiles(inParams, ctx);
481 public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
482 ctx.setAttribute("data-source", "Request");
483 ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
484 ctx.setAttribute("file-category", "configuration_block");
485 saveConfigFiles(inParams, ctx);
488 public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
489 ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
490 ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
491 ctx.setAttribute("file-category", "config_data");
492 saveConfigFiles(inParams, ctx);
495 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
496 throws SvcLogicException {
498 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
500 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
501 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
502 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
503 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
505 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
507 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
508 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
510 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
511 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
512 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
513 log.info("getConfigFilesByVnfVmNCategory Successful "
514 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
515 } catch (Exception e) {
516 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
517 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
518 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
519 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
521 throw new SvcLogicException(e.getMessage());
525 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
526 throws SvcLogicException {
528 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
530 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
532 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
534 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
535 throw new Exception("Unable to get download config template.");
537 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
538 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
539 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
540 log.info("getDownloadConfigTemplateByVnf Successful "
541 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
542 } catch (Exception e) {
543 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
544 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
545 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
546 log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
548 throw new SvcLogicException(e.getMessage());
552 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
554 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
556 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
557 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
561 SvcLogicContext logctx = new SvcLogicContext();
562 String escapedMessage = EscapeUtils.escapeSql(message);
564 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
565 logctx.setAttribute("log-message-type", messageType);
566 logctx.setAttribute("log-message", escapedMessage);
568 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
569 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
571 logctx.setAttribute("log-message", null);
573 if (status == QueryStatus.FAILURE)
574 throw new Exception("Unable to insert into config_transaction_log");
576 } catch (Exception e) {
577 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
578 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
579 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
581 throw new SvcLogicException(e.getMessage());
585 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
587 log.info("Received getVnfcReference call with params : " + inParams);
589 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
590 QueryStatus status = null;
593 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
594 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
596 if (status == QueryStatus.FAILURE)
597 throw new Exception("Unable to Read vnfc-reference");
599 // else if (status == QueryStatus.NOT_FOUND ) {
600 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
602 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
603 throw new Exception("Unable to Read vnfc reference");
607 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
608 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
609 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
610 log.info("getVnfcReference Successful ");
611 } catch (Exception e) {
612 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
613 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
614 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
615 log.error("Failed in getVnfcReference " + e.getMessage());
617 throw new SvcLogicException(e.getMessage());
621 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
622 log.info("Received getCapability call with params : " + inParams);
623 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
624 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
625 String caplevel = inParams.get("caplevel");
626 String findCapability = inParams.get("checkCapability");
627 String vServerId = inParams.get("vServerId");
628 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
629 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
630 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
631 log.info("getCapability Successful - No need for capability check for this action");
635 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
636 log.info("getCapability::returned from DB::+cap");
637 if (StringUtils.isBlank(cap)) {
638 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
639 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
640 log.info("getCapability Successful - No capability blocks found");
643 ObjectMapper mapper = new ObjectMapper();
644 JsonNode caps = mapper.readTree(cap);
645 log.info("From DB = " + caps);
646 JsonNode capabilities = caps.get("capabilities");
647 log.info("capabilities = " + capabilities);
648 if (caplevel != null && !caplevel.isEmpty()) {
649 JsonNode subCapabilities = capabilities.get(caplevel);
650 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
651 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
652 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
653 ctx.setAttribute("capabilities", "None");
654 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
655 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
656 log.info("getCapability Successful ");
659 if (findCapability != null && !findCapability.isEmpty()) {
660 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
661 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL))
662 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
664 ctx.setAttribute("capabilities", "Supported");
666 ctx.setAttribute("capabilities", "Not-Supported");
669 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
673 ctx.setAttribute(responsePrefix + "capabilities", capabilities.toString());
674 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
675 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
676 log.info("getCapability Successful ");
677 } catch (Exception e) {
678 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
679 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
680 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
681 log.error("Failed in getCapability " + e.getMessage());
683 throw new SvcLogicException(e.getMessage());
687 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
688 JsonNode subCapabilities) throws Exception {
689 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
691 if (subCapabilities.size() == 0) {
692 ctx.setAttribute("capabilities", "None");
693 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
696 JsonNode vmCaps = null;
697 for (JsonNode cap : subCapabilities) {
698 if (null != cap && null != cap.get(findCapability)
699 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
700 vmCaps = cap.get(findCapability);
701 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
706 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
707 ctx.setAttribute("capabilities", "Not-Supported");
708 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
712 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
713 if (StringUtils.isBlank(vnfcFunctionCode)) {
714 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
715 ctx.setAttribute("capabilities", "Not-Supported");
719 if (vmCaps.toString().contains(vnfcFunctionCode))
720 ctx.setAttribute("capabilities", "Supported");
722 ctx.setAttribute("capabilities", "Not-Supported");
723 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute("capabilities"));
726 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) throws Exception {
727 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
728 for (Object key : ctx.getAttributeKeySet()) {
729 String parmName = (String) key;
730 String parmValue = ctx.getAttribute(parmName);
731 log.info(parmName + "=" + parmValue);
734 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
735 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
736 return vnfcFunctionCode;
739 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
740 boolean capabilityCheckNeeded = true;
741 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
742 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<AppcDataServiceConstant.ACTIONS>(
743 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
744 for (AppcDataServiceConstant.ACTIONS action : actionList) {
745 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
746 capabilityCheckNeeded = false;
751 return capabilityCheckNeeded;