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 java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
30 import org.apache.commons.lang3.StringUtils;
31 import org.onap.appc.data.services.AppcDataServiceConstant;
32 import org.onap.appc.data.services.db.DGGeneralDBService;
33 import org.onap.appc.data.services.utils.EscapeUtils;
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;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
38 import com.att.eelf.configuration.EELFLogger;
39 import com.att.eelf.configuration.EELFManager;
40 import com.fasterxml.jackson.databind.JsonNode;
41 import com.fasterxml.jackson.databind.ObjectMapper;
43 public class ConfigResourceNode implements SvcLogicJavaPlugin {
45 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
47 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
49 log.info("Received getConfigFiles call with params : " + inParams);
51 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
55 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
56 DGGeneralDBService db = DGGeneralDBService.initialise();
57 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig",
58 "device_configuration");
60 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
61 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
63 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success",
64 "configuration_success");
66 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
67 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
69 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure",
70 "configuration_error");
72 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
73 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
75 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log");
77 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
78 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
81 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
82 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
83 log.info("GetConfigFileReference Successful ");
84 } catch (Exception e) {
85 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
86 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
87 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
88 log.error("Failed in GetConfigFileReference " + e.getMessage());
90 throw new SvcLogicException(e.getMessage());
94 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
96 log.info("Received getDeviceInfo call with params : " + inParams);
98 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
102 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
103 DGGeneralDBService db = DGGeneralDBService.initialise();
105 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
107 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
108 throw new Exception("Unable to Read device_interface_protocol");
110 status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
111 if (status == QueryStatus.FAILURE)
112 throw new Exception("Unable to Read configure_action_dg");
114 if (status == QueryStatus.NOT_FOUND) {
115 status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");
117 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
118 throw new Exception("Unable to Read configure_action_dg");
123 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
124 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
125 log.info("getCommonConfigInfo Successful ");
126 } catch (Exception e) {
127 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
128 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
129 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
130 log.error("Failed in getCommonConfigInfo " + e.getMessage());
132 throw new SvcLogicException(e.getMessage());
137 // fileCategory Can be config_template, parameter_definitions, parameter_yang
138 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
140 log.info("Received getTemplate call with params : " + inParams);
143 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
144 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
145 String templateName = ctx.getAttribute("template-name");
146 QueryStatus status = null;
147 String responsePrefix1 = "";
151 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
152 log.info("RESPONSEPREFIX : " + responsePrefix);
153 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
155 DGGeneralDBService db = DGGeneralDBService.initialise();
157 if (StringUtils.isBlank(templateName)) {
159 // if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
162 status = db.getTemplate(ctx, responsePrefix, fileCategory);
163 if (status == QueryStatus.FAILURE)
164 throw new Exception("Unable to Read " + fileCategory);
167 if (status == QueryStatus.NOT_FOUND) {
170 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
172 if (status == QueryStatus.FAILURE)
173 throw new Exception("Unable to Read " + fileCategory);
175 if (status == QueryStatus.NOT_FOUND) {
177 // status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
179 // if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
180 throw new Exception("Unable to Read " + fileCategory);
185 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
187 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
188 throw new Exception("Unable to Read " + fileCategory + " template");
192 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
193 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
194 log.info("GetTemplate Successful ");
195 } catch (Exception e) {
196 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
197 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
198 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
199 log.error("Failed in getTemplate " + e.getMessage());
201 throw new SvcLogicException(e.getMessage());
205 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
207 log.info("Received saveConfigFiles call with params : " + inParams);
209 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
213 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
214 DGGeneralDBService db = DGGeneralDBService.initialise();
215 QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
217 if (status == QueryStatus.FAILURE)
218 throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
220 status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
222 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
223 throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
225 status = db.savePrepareRelationship(ctx, "tmp.preparerel",
226 ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
227 if (status == QueryStatus.FAILURE)
228 throw new Exception("Unable to save prepare_relationship");
230 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
231 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
232 log.info("saveConfigFiles Successful ");
233 } catch (Exception e) {
234 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
235 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
236 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
237 log.error("Failed in saveConfigFiles " + e.getMessage());
239 throw new SvcLogicException(e.getMessage());
243 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
245 log.info("Received updateUploadConfig call with params : " + inParams);
247 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
251 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
252 DGGeneralDBService db = DGGeneralDBService.initialise();
254 ctx.setAttribute("tmp.escaped.devicerunningconfig",
255 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
257 QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
259 if (status == QueryStatus.FAILURE)
260 throw new Exception("Unable to Save configuration in upload_config");
262 status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
264 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
265 throw new Exception("Unable to get record from upload_config");
267 status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
268 Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
269 if (status == QueryStatus.FAILURE)
270 throw new Exception("Unable to upload upload_config");
272 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
273 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
274 log.info("updateUploadConfig Successful ");
275 } catch (Exception e) {
276 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
277 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
278 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
279 log.error("Failed in updateUploadConfig " + e.getMessage());
281 throw new SvcLogicException(e.getMessage());
285 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
287 log.info("Received savePrepareRelationship call with params : " + inParams);
289 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
290 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
291 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
294 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
295 DGGeneralDBService db = DGGeneralDBService.initialise();
297 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
298 if (status == QueryStatus.FAILURE)
299 throw new Exception("Unable to save prepare_relationship");
301 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
302 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
303 log.info("savePrepareRelationship Successful ");
304 } catch (Exception e) {
305 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
306 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
307 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
308 log.error("Failed in saveConfigFiles " + e.getMessage());
310 throw new SvcLogicException(e.getMessage());
314 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
316 log.info("Received saveConfigBlock call with params : " + inParams);
318 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
322 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
323 ctx.setAttribute("tmp.convertconfig.escapeData", EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
324 DGGeneralDBService db = DGGeneralDBService.initialise();
326 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
327 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
328 ctx.getAttribute("configuration"));
331 saveConfigurationBlock(inParams, ctx);
333 ctx.setAttribute("tmp.convertconfig.escapeData",
334 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
335 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
336 ctx.getAttribute("tmp.merge.mergedData"));
338 saveConfigurationData(inParams, ctx);
341 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
342 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
343 log.info("saveConfigBlock Successful ");
344 } catch (Exception e) {
345 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
346 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
347 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
348 log.error("Failed in saveConfigBlock " + e.getMessage());
350 throw new SvcLogicException(e.getMessage());
354 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
356 log.info("Received saveTemplateConfig call with params : " + inParams);
358 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
362 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
363 DGGeneralDBService db = DGGeneralDBService.initialise();
365 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
367 ctx.setAttribute("tmp.convertconfig.escapeData",
368 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
369 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
370 ctx.getAttribute("config-template.file-content"));
373 saveConfigurationData(inParams, ctx);
375 ctx.setAttribute("tmp.convertconfig.escapeData",
376 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
377 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
378 ctx.getAttribute("tmp.merge.mergedData"));
382 QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
383 ctx.getAttribute("config-template.config-file-id"), "Y");
384 if (status == QueryStatus.FAILURE)
385 throw new Exception("Unable to save prepare_relationship");
387 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
388 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
389 log.info("saveTemplateConfig Successful ");
390 } catch (Exception e) {
391 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
392 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
393 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
394 log.error("Failed in saveTemplateConfig " + e.getMessage());
396 throw new SvcLogicException(e.getMessage());
402 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
405 log.info("Received saveStyleSheet call with params : " + inParams);
407 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
411 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
412 ctx.setAttribute("tmp.convertconfig.escapeData",
413 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
414 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
415 ctx.getAttribute("tmp.merge.mergedData"));
418 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
419 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
420 log.info("saveStyleSheet Successful ");
421 } catch (Exception e) {
422 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
423 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
424 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
425 log.error("Failed in saveStyleSheet " + e.getMessage());
427 throw new SvcLogicException(e.getMessage());
432 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
435 log.info("Received saveStyleSheet call with params : " + inParams);
437 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
438 String siteLocation = ctx.getAttribute("site-location");
440 QueryStatus status = null;
445 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
446 DGGeneralDBService db = DGGeneralDBService.initialise();
450 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
452 if (status == QueryStatus.FAILURE)
453 throw new Exception("Unable to Read smm file");
456 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
458 if (status == QueryStatus.FAILURE)
459 throw new Exception("Unable to Read intermediate_ca_chain file");
463 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
466 if (status == QueryStatus.FAILURE)
467 throw new Exception("Unable to Read server_certificate_and_key file");
470 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
471 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
472 log.info("saveStyleSheet Successful ");
473 } catch (Exception e) {
474 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
475 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
476 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
477 log.error("Failed in saveStyleSheet " + e.getMessage());
479 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", "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", "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", "config_data");
505 saveConfigFiles(inParams, ctx);
509 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
510 throws SvcLogicException {
512 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
514 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
515 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
516 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
517 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
521 DGGeneralDBService db = DGGeneralDBService.initialise();
523 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
525 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
526 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
529 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
530 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
531 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
532 log.info("getConfigFilesByVnfVmNCategory Successful "
533 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
534 } catch (Exception e) {
535 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
536 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
537 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
538 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
540 throw new SvcLogicException(e.getMessage());
545 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
546 throws SvcLogicException {
548 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
550 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
552 DGGeneralDBService db = DGGeneralDBService.initialise();
554 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
556 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
557 throw new Exception("Unable to get download config template.");
560 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
561 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
562 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
563 log.info("getDownloadConfigTemplateByVnf Successful "
564 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
565 } catch (Exception e) {
566 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
567 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
568 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
569 log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
571 throw new SvcLogicException(e.getMessage());
576 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
580 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
582 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
583 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
587 SvcLogicContext logctx = new SvcLogicContext();
589 String escapedMessage = EscapeUtils.escapeSql(message);
592 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
593 logctx.setAttribute("log-message-type", messageType);
594 logctx.setAttribute("log-message", escapedMessage);
597 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
598 DGGeneralDBService db = DGGeneralDBService.initialise();
599 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
601 logctx.setAttribute("log-message", null);
603 if (status == QueryStatus.FAILURE)
604 throw new Exception("Unable to insert into config_transaction_log");
607 } catch (Exception e) {
608 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
609 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
610 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
613 throw new SvcLogicException(e.getMessage());
619 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
621 log.info("Received getVnfcReference call with params : " + inParams);
623 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
626 QueryStatus status = null;
631 DGGeneralDBService db = DGGeneralDBService.initialise();
633 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
634 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
636 if (status == QueryStatus.FAILURE)
637 throw new Exception("Unable to Read vnfc-reference");
639 // else if (status == QueryStatus.NOT_FOUND ) {
640 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
642 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
643 throw new Exception("Unable to Read vnfc reference");
647 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
648 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
649 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
650 log.info("getVnfcReference Successful ");
651 } catch (Exception e) {
652 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
653 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
654 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
655 log.error("Failed in getVnfcReference " + e.getMessage());
657 throw new SvcLogicException(e.getMessage());
661 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
662 log.info("Received getCapability call with params : " + inParams);
663 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
664 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
665 String caplevel = inParams.get("caplevel");
666 String findCapability = inParams.get("checkCapability");
667 String vServerId = inParams.get("vServerId");
668 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
669 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
670 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
671 log.info("getCapability Successful - No need for capability check for this action");
675 DGGeneralDBService db = DGGeneralDBService.initialise();
676 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
677 log.info("getCapability::returned from DB::+cap");
678 if (StringUtils.isBlank(cap)) {
679 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
680 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
681 log.info("getCapability Successful - No capability blocks found");
684 ObjectMapper mapper = new ObjectMapper();
685 JsonNode caps = mapper.readTree(cap);
686 log.info("From DB = " + caps);
687 JsonNode capabilities = caps.get("capabilities");
688 log.info("capabilities = " + capabilities);
689 if (caplevel != null && !caplevel.isEmpty()) {
690 JsonNode subCapabilities = capabilities.get(caplevel);
691 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
692 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
693 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
694 ctx.setAttribute("capabilities", "None");
695 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
696 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
697 log.info("getCapability Successful ");
700 if (findCapability != null && !findCapability.isEmpty()) {
701 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
702 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL))
703 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
705 ctx.setAttribute("capabilities", "Supported");
707 ctx.setAttribute("capabilities", "Not-Supported");
710 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
714 ctx.setAttribute(responsePrefix + "capabilities", capabilities.toString());
715 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
716 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
717 log.info("getCapability Successful ");
718 } catch (Exception e) {
719 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
720 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
721 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
722 log.error("Failed in getCapability " + e.getMessage());
724 throw new SvcLogicException(e.getMessage());
728 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
729 JsonNode subCapabilities) throws Exception {
730 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
732 if (subCapabilities.size() == 0) {
733 ctx.setAttribute("capabilities", "None");
734 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
737 JsonNode vmCaps = null;
738 for (JsonNode cap : subCapabilities) {
739 if (null != cap && null != cap.get(findCapability)
740 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
741 vmCaps = cap.get(findCapability);
742 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
747 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
748 ctx.setAttribute("capabilities", "Not-Supported");
749 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
753 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
754 if (StringUtils.isBlank(vnfcFunctionCode)) {
755 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
756 ctx.setAttribute("capabilities", "Not-Supported");
760 if (vmCaps.toString().contains(vnfcFunctionCode))
761 ctx.setAttribute("capabilities", "Supported");
763 ctx.setAttribute("capabilities", "Not-Supported");
764 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute("capabilities"));
767 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) throws Exception {
768 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
769 for (Object key : ctx.getAttributeKeySet()) {
770 String parmName = (String) key;
771 String parmValue = ctx.getAttribute(parmName);
772 log.info(parmName + "=" + parmValue);
775 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
776 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
777 return vnfcFunctionCode;
780 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
781 boolean capabilityCheckNeeded = true;
782 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
783 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<AppcDataServiceConstant.ACTIONS>(
784 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
785 for (AppcDataServiceConstant.ACTIONS action : actionList) {
786 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
787 capabilityCheckNeeded = false;
792 return capabilityCheckNeeded;