2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.appc.data.services.node;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
28 import org.apache.commons.lang3.StringUtils;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
38 import org.onap.appc.data.services.AppcDataServiceConstant;
39 import org.onap.appc.data.services.AppcDataServiceConstant.ACTIONS;
40 import org.onap.appc.data.services.db.DGGeneralDBService;
41 import org.onap.appc.data.services.utils.EscapeUtils;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
45 public class ConfigResourceNode implements SvcLogicJavaPlugin {
47 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
49 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
51 log.info("Received getConfigFiles call with params : " + inParams);
53 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
57 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
58 DGGeneralDBService db = DGGeneralDBService.initialise();
59 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig",
60 "device_configuration");
62 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
63 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
65 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success",
66 "configuration_success");
68 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
69 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
71 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure",
72 "configuration_error");
74 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
75 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
77 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log");
79 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
80 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
83 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
84 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
85 log.info("GetConfigFileReference Successful ");
86 } catch (Exception e) {
87 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
88 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
89 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
90 log.error("Failed in GetConfigFileReference " + e.getMessage());
92 throw new SvcLogicException(e.getMessage());
96 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
98 log.info("Received getDeviceInfo call with params : " + inParams);
100 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
104 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
105 DGGeneralDBService db = DGGeneralDBService.initialise();
107 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
109 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
110 throw new Exception("Unable to Read device_interface_protocol");
112 status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
113 if (status == QueryStatus.FAILURE)
114 throw new Exception("Unable to Read configure_action_dg");
116 if (status == QueryStatus.NOT_FOUND) {
117 status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");
119 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
120 throw new Exception("Unable to Read configure_action_dg");
127 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
128 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
129 log.info("getCommonConfigInfo Successful ");
130 } catch (Exception e) {
131 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
132 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
133 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
134 log.error("Failed in getCommonConfigInfo " + e.getMessage());
136 throw new SvcLogicException(e.getMessage());
141 // fileCategory Can be config_template, parameter_definitions, parameter_yang
142 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
144 log.info("Received getTemplate call with params : " + inParams);
147 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
148 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
149 String templateName = ctx.getAttribute("template-name");
150 QueryStatus status = null;
151 String responsePrefix1 = "";
155 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
156 log.info("RESPONSEPREFIX : " + responsePrefix);
157 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
159 DGGeneralDBService db = DGGeneralDBService.initialise();
161 if (StringUtils.isBlank(templateName)) {
163 //if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
166 status = db.getTemplate(ctx, responsePrefix, fileCategory);
167 if (status == QueryStatus.FAILURE)
168 throw new Exception("Unable to Read " + fileCategory );
171 if (status == QueryStatus.NOT_FOUND) {
174 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
176 if (status == QueryStatus.FAILURE)
177 throw new Exception("Unable to Read " + fileCategory );
179 if (status == QueryStatus.NOT_FOUND) {
181 //status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
183 //if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
184 throw new Exception("Unable to Read " + fileCategory );
189 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
191 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
192 throw new Exception("Unable to Read " + fileCategory + " template");
196 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
197 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
198 log.info("GetTemplate Successful ");
199 } catch (Exception e) {
200 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
201 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
202 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
203 log.error("Failed in getTemplate " + e.getMessage());
205 throw new SvcLogicException(e.getMessage());
209 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
211 log.info("Received saveConfigFiles call with params : " + inParams);
213 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
217 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
218 DGGeneralDBService db = DGGeneralDBService.initialise();
219 QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
221 if (status == QueryStatus.FAILURE)
222 throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
224 status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
226 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
227 throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
229 status = db.savePrepareRelationship(ctx, "tmp.preparerel",
230 ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
231 if (status == QueryStatus.FAILURE)
232 throw new Exception("Unable to save prepare_relationship");
234 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
235 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
236 log.info("saveConfigFiles Successful ");
237 } catch (Exception e) {
238 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
239 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
240 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
241 log.error("Failed in saveConfigFiles " + e.getMessage());
243 throw new SvcLogicException(e.getMessage());
247 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
249 log.info("Received updateUploadConfig call with params : " + inParams);
251 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
255 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
256 DGGeneralDBService db = DGGeneralDBService.initialise();
258 ctx.setAttribute("tmp.escaped.devicerunningconfig",
259 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
261 QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
263 if (status == QueryStatus.FAILURE)
264 throw new Exception("Unable to Save configuration in upload_config");
266 /*status = db.getMaxUploadConfigFileId(ctx, "tmp.uploadconfigmax");
268 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
269 throw new Exception("Unable to get record from upload_config");
271 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
272 Integer.parseInt(ctx.getAttribute("tmp.uploadconfigmax.uploadconfigid")));
273 if (status == QueryStatus.FAILURE)
274 throw new Exception("Unable to upload upload_config");*/
276 status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
278 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
279 throw new Exception("Unable to get record from upload_config");
281 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
282 Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
283 if (status == QueryStatus.FAILURE)
284 throw new Exception("Unable to upload upload_config");
286 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
287 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
288 log.info("updateUploadConfig Successful ");
289 } catch (Exception e) {
290 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
291 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
292 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
293 log.error("Failed in updateUploadConfig " + e.getMessage());
295 throw new SvcLogicException(e.getMessage());
299 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
301 log.info("Received savePrepareRelationship call with params : " + inParams);
303 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
304 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
305 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
308 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
309 DGGeneralDBService db = DGGeneralDBService.initialise();
311 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
312 if (status == QueryStatus.FAILURE)
313 throw new Exception("Unable to save prepare_relationship");
315 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
316 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
317 log.info("savePrepareRelationship Successful ");
318 } catch (Exception e) {
319 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
320 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
321 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
322 log.error("Failed in saveConfigFiles " + e.getMessage());
324 throw new SvcLogicException(e.getMessage());
328 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
330 log.info("Received saveConfigBlock call with params : " + inParams);
332 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
336 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
337 ctx.setAttribute("tmp.convertconfig.escapeData",
338 EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
339 DGGeneralDBService db = DGGeneralDBService.initialise();
341 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
342 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
343 ctx.getAttribute("configuration"));
346 saveConfigurationBlock(inParams, ctx);
348 ctx.setAttribute("tmp.convertconfig.escapeData",
349 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
350 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
351 ctx.getAttribute("tmp.merge.mergedData"));
353 saveConfigurationData(inParams, ctx);
356 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
357 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
358 log.info("saveConfigBlock Successful ");
359 } catch (Exception e) {
360 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
361 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
362 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
363 log.error("Failed in saveConfigBlock " + e.getMessage());
365 throw new SvcLogicException(e.getMessage());
369 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
371 log.info("Received saveTemplateConfig call with params : " + inParams);
373 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
377 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
378 DGGeneralDBService db = DGGeneralDBService.initialise();
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, "tmp.preparerel",
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());
418 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
421 log.info("Received saveStyleSheet call with params : " + inParams);
423 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
427 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
428 ctx.setAttribute("tmp.convertconfig.escapeData",
429 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
430 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
431 ctx.getAttribute("tmp.merge.mergedData"));
434 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
435 log.info("saveStyleSheet Successful ");
436 } catch (Exception e) {
437 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
438 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
439 log.error("Failed in saveStyleSheet " + e.getMessage());
441 throw new SvcLogicException(e.getMessage());
446 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
449 log.info("Received saveStyleSheet call with params : " + inParams);
451 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
452 String siteLocation = ctx.getAttribute("site-location");
454 QueryStatus status = null;
459 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
460 DGGeneralDBService db = DGGeneralDBService.initialise();
464 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
466 if ( status == QueryStatus.FAILURE )
467 throw new Exception("Unable to Read smm file");
470 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
472 if ( status == QueryStatus.FAILURE )
473 throw new Exception("Unable to Read intermediate_ca_chain file");
478 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key", siteLocation);
480 if ( status == QueryStatus.FAILURE )
481 throw new Exception("Unable to Read server_certificate_and_key file");
484 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
485 log.info("saveStyleSheet Successful ");
486 } catch (Exception e) {
487 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
488 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
489 log.error("Failed in saveStyleSheet " + e.getMessage());
491 throw new SvcLogicException(e.getMessage());
496 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
497 String fileContent, String deviceConfig) throws SvcLogicException {
498 ctx.setAttribute("data-source", dataSource);
499 ctx.setAttribute("file-content", fileContent);
500 ctx.setAttribute("file-category", "device_configuration");
501 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
503 saveConfigFiles(inParams, ctx);
506 public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
507 ctx.setAttribute("data-source", "Request");
508 ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
509 ctx.setAttribute("file-category", "configuration_block");
510 saveConfigFiles(inParams, ctx);
513 public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
514 ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
515 ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
516 ctx.setAttribute("file-category", "config_data");
517 saveConfigFiles(inParams, ctx);
521 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
523 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
525 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
526 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
527 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
528 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
532 DGGeneralDBService db = DGGeneralDBService.initialise();
534 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
536 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
537 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
540 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
541 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
542 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
543 log.info("getConfigFilesByVnfVmNCategory Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
544 } catch (Exception e) {
545 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
546 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
547 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
548 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
550 throw new SvcLogicException(e.getMessage());
555 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
557 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
559 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
561 DGGeneralDBService db = DGGeneralDBService.initialise();
563 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
565 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
566 throw new Exception("Unable to get download config template.");
569 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
570 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
571 log.info("getDownloadConfigTemplateByVnf Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
572 } catch (Exception e) {
573 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
574 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
575 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
576 log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
578 throw new SvcLogicException(e.getMessage());
583 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
587 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
589 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
590 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
594 SvcLogicContext logctx = new SvcLogicContext();
596 String escapedMessage = EscapeUtils.escapeSql(message);
599 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
600 logctx.setAttribute("log-message-type", messageType);
601 logctx.setAttribute("log-message", escapedMessage);
604 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
605 DGGeneralDBService db = DGGeneralDBService.initialise();
606 QueryStatus status = db.saveConfigTransactionLog( logctx, responsePrefix);
608 logctx.setAttribute("log-message", null);
610 if (status == QueryStatus.FAILURE)
611 throw new Exception("Unable to insert into config_transaction_log");
614 } catch (Exception e) {
615 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
616 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
617 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
620 throw new SvcLogicException(e.getMessage());
626 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
628 log.info("Received getVnfcReference call with params : " + inParams);
630 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
633 QueryStatus status = null;
638 DGGeneralDBService db = DGGeneralDBService.initialise();
640 if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
641 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
643 if ( status == QueryStatus.FAILURE)
644 throw new Exception("Unable to Read vnfc-reference");
646 //else if (status == QueryStatus.NOT_FOUND ) {
647 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
649 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
650 throw new Exception("Unable to Read vnfc reference");
654 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
655 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
656 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
657 log.info("getVnfcReference Successful ");
658 } catch (Exception e) {
659 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
660 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
661 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
662 log.error("Failed in getVnfcReference " + e.getMessage());
664 throw new SvcLogicException(e.getMessage());
668 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
669 log.info("Received getCapability call with params : " + inParams);
670 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
671 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
672 String caplevel = inParams.get("caplevel");
673 String findCapability = inParams.get("checkCapability");
674 String vServerId=inParams.get("vServerId");
675 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability))
677 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
678 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
679 log.info("getCapability Successful - No need for capability check for this action");
683 DGGeneralDBService db = DGGeneralDBService.initialise();
684 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
685 log.info("getCapability::returned from DB::+cap");
686 if (StringUtils.isBlank(cap)) {
687 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
688 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
689 log.info("getCapability Successful - No capability blocks found");
692 ObjectMapper mapper = new ObjectMapper();
693 JsonNode caps = mapper.readTree(cap);
694 log.info("From DB = " + caps);
695 JsonNode capabilities = caps.get("capabilities");
696 log.info("capabilities = " + capabilities);
697 if(caplevel !=null && !caplevel.isEmpty()){
698 JsonNode subCapabilities = capabilities.get(caplevel);
699 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
700 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
701 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size()==0)) {
702 ctx.setAttribute("capabilities", "None");
703 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
704 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
705 log.info("getCapability Successful ");
708 if(findCapability !=null && !findCapability.isEmpty()){
709 if(subCapabilities != null && subCapabilities.toString().contains(findCapability)){
710 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL))
711 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
713 ctx.setAttribute("capabilities" , "Supported");
716 ctx.setAttribute("capabilities" , "Not-Supported");
721 ctx.setAttribute(responsePrefix + "capabilities." + caplevel,
722 subCapabilities.toString());
727 ctx.setAttribute(responsePrefix + "capabilities",
728 capabilities.toString());
729 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
730 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
731 log.info("getCapability Successful ");
732 } catch (Exception e) {
733 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
734 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
735 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
736 log.error("Failed in getCapability " + e.getMessage());
738 throw new SvcLogicException(e.getMessage());
742 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
743 JsonNode subCapabilities) throws Exception {
744 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
746 if (subCapabilities.size()==0) {
747 ctx.setAttribute("capabilities", "None");
748 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
751 JsonNode vmCaps = null;
752 for (JsonNode cap : subCapabilities) {
753 if (null != cap && null != cap.get(findCapability)
754 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
755 vmCaps = cap.get(findCapability);
756 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
761 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
762 ctx.setAttribute("capabilities", "Not-Supported");
763 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
767 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
768 if (vmCaps != null && vmCaps.toString().contains(vnfcFunctionCode))
769 ctx.setAttribute("capabilities", "Supported");
771 ctx.setAttribute("capabilities", "Not-Supported");
772 log.info("End processCapabilitiesForVMLevel():capabilities is ::"+ctx.getAttribute("capabilities"));
775 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) throws Exception {
776 log.debug("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
777 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
778 log.debug("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
779 return vnfcFunctionCode;
782 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
783 boolean capabilityCheckNeeded = true;
784 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
785 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<AppcDataServiceConstant.ACTIONS>(
786 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
787 for (AppcDataServiceConstant.ACTIONS action : actionList) {
788 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
789 capabilityCheckNeeded = false;
794 return capabilityCheckNeeded;
799 /*public void getUploadConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
801 log.info("Received getUploadConfigInfo call with params : " + inParams);
803 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
805 String uploadConfigId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_UPLOAD_CONFIG_ID);
806 QueryStatus status = null;
812 DGGeneralDBService db = DGGeneralDBService.initialise();
814 if ( uploadConfigId != null )
815 id = Integer.parseInt(uploadConfigId);
817 status = db.getUploadConfigInfo(ctx, responsePrefix,id);
819 if ( status == QueryStatus.FAILURE || status == QueryStatus.NOT_FOUND)
820 throw new Exception("Unable to Read upload-config");
823 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
824 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
825 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
826 log.info("getUploadConfigInfo Successful ");
827 } catch (Exception e) {
828 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
829 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
830 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
831 log.error("Failed in getUploadConfigInfo " + e.getMessage());
833 throw new SvcLogicException(e.getMessage());