2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.data.services.node;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.databind.JsonNode;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.List;
34 import org.apache.commons.lang3.StringUtils;
35 import org.onap.appc.data.services.AppcDataServiceConstant;
36 import org.onap.appc.data.services.db.DGGeneralDBService;
37 import org.onap.appc.data.services.utils.EscapeUtils;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
43 public class ConfigResourceNode implements SvcLogicJavaPlugin {
45 static final String DEVICE_CONF_PREFIX = "configfilereference-deviceconfig";
46 static final String DEVICE_CONF_FILE_TYPE = "device_configuration";
48 static final String SUCCESS_PREFIX = "configfilereference-success";
49 static final String SUCCESS_FILE_TYPE = "configuration_success";
51 static final String FAILURE_PREFIX = "configfilereference-failure";
52 static final String FAILURE_FILE_TYPE = "configuration_error";
54 static final String LOG_PREFIX = "configfilereference-log";
55 static final String LOG_FILE_TYPE = "log";
57 static final String DEVICE_PROTOCOL_PREFIX = "tmp.deviceinterfaceprotocol";
58 static final String CONF_ACTION_PREFIX = "tmp.configureactiondg";
60 static final String CONFIG_FILES_PREFIX = "tmp.configFiles";
61 static final String MAX_CONF_FILE_PREFIX = "tmp.configfilesmax";
62 static final String UPLOAD_CONFIG_PREFIX = "tmp.uploadConfig";
63 static final String UPLOAD_CONFIG_INFO_PREFIX = "tmp.uploadConfigInfo";
65 static final String PREPARE_RELATIONSHIP_PARAM = "tmp.preparerel";
66 static final String CONFIG_FILE_ID_PARAM = "tmp.configfilesmax.configfileid";
67 static final String FILE_CATEGORY_PARAM = "file-category";
68 static final String UPLOAD_CONFIG_ID_PARAM = "tmp.uploadConfigInfo.UPLOAD-CONFIG-ID";
70 static final String SDC_IND = "N";
72 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
73 private final DGGeneralDBService db;
76 * Constructor which provide default DB service
78 public ConfigResourceNode() {
79 db = DGGeneralDBService.initialise();
83 * Constructor which allow to provide custom DB service, prefer to use no-arg constructor
85 public ConfigResourceNode(DGGeneralDBService dbService) {
89 public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
91 log.info("Received getConfigFiles call with params : " + inParams);
92 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
95 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
96 QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE);
98 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
99 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
101 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, SUCCESS_PREFIX, SUCCESS_FILE_TYPE);
103 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
104 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
106 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, FAILURE_PREFIX, FAILURE_FILE_TYPE);
108 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
109 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
111 status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, LOG_PREFIX, LOG_FILE_TYPE);
113 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
114 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
116 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
117 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
118 log.info("GetConfigFileReference Successful ");
119 } catch (Exception e) {
120 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
121 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
122 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
123 log.error("Failed in GetConfigFileReference " + e.getMessage());
125 throw new SvcLogicException(e.getMessage());
129 public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
131 log.info("Received getDeviceInfo call with params : " + inParams);
132 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
135 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
136 QueryStatus status = db.getDeviceProtocolByVnfType(ctx, DEVICE_PROTOCOL_PREFIX);
138 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
139 throw new Exception("Unable to Read device_interface_protocol");
141 status = db.getConfigureActionDGByVnfTypeNAction(ctx, CONF_ACTION_PREFIX);
142 if (status == QueryStatus.FAILURE)
143 throw new Exception("Unable to Read configure_action_dg");
145 if (status == QueryStatus.NOT_FOUND) {
146 status = db.getConfigureActionDGByVnfType(ctx, CONF_ACTION_PREFIX);
148 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
149 throw new Exception("Unable to Read configure_action_dg");
152 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
153 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
154 log.info("getCommonConfigInfo Successful ");
155 } catch (Exception e) {
156 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
157 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
158 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
159 log.error("Failed in getCommonConfigInfo " + e.getMessage());
161 throw new SvcLogicException(e.getMessage());
166 * FileCategory can be config_template, parameter_definitions, parameter_yang
168 public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
170 log.info("Received getTemplate call with params : " + inParams);
172 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
173 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
174 String templateName = ctx.getAttribute("template-name");
175 QueryStatus status = null;
176 String responsePrefix1 = "";
180 responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
181 log.info("RESPONSEPREFIX : " + responsePrefix);
182 log.info("RESPONSEPREFIX1 : " + responsePrefix1);
184 if (StringUtils.isBlank(templateName)) {
186 // if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
188 status = db.getTemplate(ctx, responsePrefix, fileCategory);
189 if (status == QueryStatus.FAILURE)
190 throw new Exception("Unable to Read " + fileCategory);
193 if (status == QueryStatus.NOT_FOUND) {
196 status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
198 if (status == QueryStatus.FAILURE)
199 throw new Exception("Unable to Read " + fileCategory);
201 if (status == QueryStatus.NOT_FOUND) {
203 // status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
205 // if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
206 throw new Exception("Unable to Read " + fileCategory);
211 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
213 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
214 throw new Exception("Unable to Read " + fileCategory + " template");
217 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
218 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
219 log.info("GetTemplate Successful ");
220 } catch (Exception e) {
221 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
222 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
223 ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
224 log.error("Failed in getTemplate " + e.getMessage());
226 throw new SvcLogicException(e.getMessage());
230 public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
232 log.info("Received saveConfigFiles call with params : " + inParams);
234 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
238 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
239 QueryStatus status = db.saveConfigFiles(ctx, CONFIG_FILES_PREFIX);
241 if (status == QueryStatus.FAILURE)
242 throw new Exception("Unable to Save " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " in configfiles");
244 status = db.getMaxConfigFileId(ctx, MAX_CONF_FILE_PREFIX, ctx.getAttribute(FILE_CATEGORY_PARAM));
246 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
247 throw new Exception("Unable to get " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " from configfiles");
249 status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
250 ctx.getAttribute(CONFIG_FILE_ID_PARAM), SDC_IND);
251 if (status == QueryStatus.FAILURE)
252 throw new Exception("Unable to save prepare_relationship");
254 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
255 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
256 log.info("saveConfigFiles Successful ");
257 } catch (Exception e) {
258 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
259 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
260 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
261 log.error("Failed in saveConfigFiles " + e.getMessage());
263 throw new SvcLogicException(e.getMessage());
267 public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
269 log.info("Received updateUploadConfig call with params : " + inParams);
271 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
275 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
277 ctx.setAttribute("tmp.escaped.devicerunningconfig",
278 EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
280 QueryStatus status = db.saveUploadConfig(ctx, UPLOAD_CONFIG_PREFIX);
282 if (status == QueryStatus.FAILURE)
283 throw new Exception("Unable to Save configuration in upload_config");
285 status = db.getUploadConfigInfo(ctx, UPLOAD_CONFIG_INFO_PREFIX);
287 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
288 throw new Exception("Unable to get record from upload_config");
290 status = db.updateUploadConfig(ctx, UPLOAD_CONFIG_PREFIX,
291 Integer.parseInt(ctx.getAttribute(UPLOAD_CONFIG_ID_PARAM)));
292 if (status == QueryStatus.FAILURE)
293 throw new Exception("Unable to upload upload_config");
295 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
296 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
297 log.info("updateUploadConfig Successful ");
298 } catch (Exception e) {
299 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
300 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
301 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
302 log.error("Failed in updateUploadConfig " + e.getMessage());
304 throw new SvcLogicException(e.getMessage());
308 public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
310 log.info("Received savePrepareRelationship call with params : " + inParams);
312 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
313 String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
314 String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
317 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
319 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM, fileId, sdcArtifactInd);
320 if (status == QueryStatus.FAILURE)
321 throw new Exception("Unable to save prepare_relationship");
323 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
324 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
325 log.info("savePrepareRelationship Successful ");
326 } catch (Exception e) {
327 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
328 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
329 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
330 log.error("Failed in saveConfigFiles " + e.getMessage());
332 throw new SvcLogicException(e.getMessage());
336 public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
338 log.info("Received saveConfigBlock call with params : " + inParams);
340 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
343 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
344 ctx.setAttribute("tmp.convertconfig.escapeData", EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
346 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
347 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
348 ctx.getAttribute("configuration"));
351 saveConfigurationBlock(inParams, ctx);
353 ctx.setAttribute("tmp.convertconfig.escapeData",
354 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
355 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
356 ctx.getAttribute("tmp.merge.mergedData"));
358 saveConfigurationData(inParams, ctx);
361 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
362 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
363 log.info("saveConfigBlock Successful ");
364 } catch (Exception e) {
365 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
366 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
367 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
368 log.error("Failed in saveConfigBlock " + e.getMessage());
370 throw new SvcLogicException(e.getMessage());
374 public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
376 log.info("Received saveTemplateConfig call with params : " + inParams);
378 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
381 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
383 if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
385 ctx.setAttribute("tmp.convertconfig.escapeData",
386 EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
387 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
388 ctx.getAttribute("config-template.file-content"));
391 saveConfigurationData(inParams, ctx);
393 ctx.setAttribute("tmp.convertconfig.escapeData",
394 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
395 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
396 ctx.getAttribute("tmp.merge.mergedData"));
400 QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
401 ctx.getAttribute("config-template.config-file-id"), "Y");
402 if (status == QueryStatus.FAILURE)
403 throw new Exception("Unable to save prepare_relationship");
405 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
406 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
407 log.info("saveTemplateConfig Successful ");
408 } catch (Exception e) {
409 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
410 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
411 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
412 log.error("Failed in saveTemplateConfig " + e.getMessage());
414 throw new SvcLogicException(e.getMessage());
418 public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
420 log.info("Received saveStyleSheet call with params : " + inParams);
422 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
426 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
427 ctx.setAttribute("tmp.convertconfig.escapeData",
428 EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
429 saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
430 ctx.getAttribute("tmp.merge.mergedData"));
432 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
433 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
434 log.info("saveStyleSheet Successful ");
435 } catch (Exception e) {
436 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
437 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());
445 public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
447 log.info("Received saveStyleSheet call with params : " + inParams);
449 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
450 String siteLocation = ctx.getAttribute("site-location");
452 QueryStatus status = null;
456 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
458 status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation);
460 if (status == QueryStatus.FAILURE)
461 throw new Exception("Unable to Read smm file");
463 status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
465 if (status == QueryStatus.FAILURE)
466 throw new Exception("Unable to Read intermediate_ca_chain file");
468 status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key",
471 if (status == QueryStatus.FAILURE)
472 throw new Exception("Unable to Read server_certificate_and_key file");
474 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
475 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
476 log.info("saveStyleSheet Successful ");
477 } catch (Exception e) {
478 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
479 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
480 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
481 log.error("Failed in saveStyleSheet " + e.getMessage());
483 throw new SvcLogicException(e.getMessage());
487 public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
488 String fileContent, String deviceConfig) throws SvcLogicException {
489 ctx.setAttribute("data-source", dataSource);
490 ctx.setAttribute("file-content", fileContent);
491 ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
492 ctx.setAttribute("deviceconfig-file-content", deviceConfig);
494 saveConfigFiles(inParams, ctx);
497 public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
498 ctx.setAttribute("data-source", "Request");
499 ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
500 ctx.setAttribute(FILE_CATEGORY_PARAM, "configuration_block");
501 saveConfigFiles(inParams, ctx);
504 public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
505 ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
506 ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
507 ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
508 saveConfigFiles(inParams, ctx);
511 public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx)
512 throws SvcLogicException {
514 log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
516 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
517 String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
518 String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
519 String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
521 QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
523 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
524 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
526 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
527 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
528 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
529 log.info("getConfigFilesByVnfVmNCategory Successful "
530 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
531 } catch (Exception e) {
532 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
533 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
534 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
535 log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
537 throw new SvcLogicException(e.getMessage());
541 public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx)
542 throws SvcLogicException {
544 log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
546 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
548 QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
550 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
551 throw new Exception("Unable to get download config template.");
553 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
554 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
555 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
556 log.info("getDownloadConfigTemplateByVnf Successful "
557 + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
558 } catch (Exception e) {
559 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
560 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
561 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
562 log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
564 throw new SvcLogicException(e.getMessage());
568 public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
570 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
572 String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
573 String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
577 SvcLogicContext logctx = new SvcLogicContext();
578 String escapedMessage = EscapeUtils.escapeSql(message);
580 logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
581 logctx.setAttribute("log-message-type", messageType);
582 logctx.setAttribute("log-message", escapedMessage);
584 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
585 QueryStatus status = db.saveConfigTransactionLog(logctx, responsePrefix);
587 logctx.setAttribute("log-message", null);
589 if (status == QueryStatus.FAILURE)
590 throw new Exception("Unable to insert into config_transaction_log");
592 } catch (Exception e) {
593 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
594 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
595 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
597 throw new SvcLogicException(e.getMessage());
601 public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
603 log.info("Received getVnfcReference call with params : " + inParams);
605 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
606 QueryStatus status = null;
609 if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
610 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
612 if (status == QueryStatus.FAILURE)
613 throw new Exception("Unable to Read vnfc-reference");
615 // else if (status == QueryStatus.NOT_FOUND ) {
616 status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
618 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
619 throw new Exception("Unable to Read vnfc reference");
623 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
624 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
625 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
626 log.info("getVnfcReference Successful ");
627 } catch (Exception e) {
628 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
629 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
630 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
631 log.error("Failed in getVnfcReference " + e.getMessage());
633 throw new SvcLogicException(e.getMessage());
637 public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
638 log.info("Received getCapability call with params : " + inParams);
639 String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
640 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
641 String caplevel = inParams.get("caplevel");
642 String findCapability = inParams.get("checkCapability");
643 String vServerId = inParams.get("vServerId");
644 if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) {
645 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
646 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
647 log.info("getCapability Successful - No need for capability check for this action");
651 String cap = db.getCapability(ctx, inParams.get("vnf-type"));
652 log.info("getCapability::returned from DB::+cap");
653 if (StringUtils.isBlank(cap)) {
654 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
655 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
656 log.info("getCapability Successful - No capability blocks found");
659 ObjectMapper mapper = new ObjectMapper();
660 JsonNode caps = mapper.readTree(cap);
661 log.info("From DB = " + caps);
662 JsonNode capabilities = caps.get("capabilities");
663 log.info("capabilities = " + capabilities);
664 if (caplevel != null && !caplevel.isEmpty()) {
665 JsonNode subCapabilities = capabilities.get(caplevel);
666 log.info("subCapabilities = " + caplevel + " : " + subCapabilities);
667 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL)
668 && (null == subCapabilities || subCapabilities.isNull() || subCapabilities.size() == 0)) {
669 ctx.setAttribute("capabilities", "None");
670 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
671 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
672 log.info("getCapability Successful ");
675 if (findCapability != null && !findCapability.isEmpty()) {
676 if (subCapabilities != null && subCapabilities.toString().contains(findCapability)) {
677 if (caplevel.equalsIgnoreCase(AppcDataServiceConstant.CAPABILITY_VM_LEVEL))
678 processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
680 ctx.setAttribute("capabilities", "Supported");
682 ctx.setAttribute("capabilities", "Not-Supported");
685 ctx.setAttribute(responsePrefix + "capabilities." + caplevel, subCapabilities.toString());
689 ctx.setAttribute(responsePrefix + "capabilities", capabilities.toString());
690 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
691 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
692 log.info("getCapability Successful ");
693 } catch (Exception e) {
694 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
695 AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
696 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
697 log.error("Failed in getCapability " + e.getMessage());
699 throw new SvcLogicException(e.getMessage());
703 public void processCapabilitiesForVMLevel(String vServerId, SvcLogicContext ctx, String findCapability,
704 JsonNode subCapabilities) throws Exception {
705 log.info("processCapabilitiesForVMLevel():::subCapabilities::" + subCapabilities.toString() + ",vServerId::"
707 if (subCapabilities.size() == 0) {
708 ctx.setAttribute("capabilities", "None");
709 log.info("processCapabilitiesForVMLevel :: No VM block found!!");
712 JsonNode vmCaps = null;
713 for (JsonNode cap : subCapabilities) {
714 if (null != cap && null != cap.get(findCapability)
715 && StringUtils.isNotBlank(cap.get(findCapability).toString())) {
716 vmCaps = cap.get(findCapability);
717 log.info("processCapabilitiesForVMLevel()::vmCaps found" + vmCaps.toString());
722 if (null == vmCaps || vmCaps.isNull() || vmCaps.size() == 0) {
723 ctx.setAttribute("capabilities", "Not-Supported");
724 log.info("processCapabilitiesForVMLevel :: Found non-empty VM block but Not desired capability!!");
728 String vnfcFunctionCode = getVnfcFunctionCodeForVserver(ctx, vServerId);
729 if (StringUtils.isBlank(vnfcFunctionCode)) {
730 log.info("processCapabilitiesForVMLevel() :: vnfcFunctionCode is not present in context!!!");
731 ctx.setAttribute("capabilities", "Not-Supported");
735 if (vmCaps.toString().contains(vnfcFunctionCode))
736 ctx.setAttribute("capabilities", "Supported");
738 ctx.setAttribute("capabilities", "Not-Supported");
739 log.info("End processCapabilitiesForVMLevel():capabilities is ::" + ctx.getAttribute("capabilities"));
742 private String getVnfcFunctionCodeForVserver(SvcLogicContext ctx, String vServerId) throws Exception {
743 log.info("getVnfcFunctionCodeForVserver()::vServerId=" + vServerId);
744 for (Object key : ctx.getAttributeKeySet()) {
745 String parmName = (String) key;
746 String parmValue = ctx.getAttribute(parmName);
747 log.info(parmName + "=" + parmValue);
750 String vnfcFunctionCode = ctx.getAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code");
751 log.info("getVnfcFunctionCodeForVserver()::vnfcFunctionCode=" + vnfcFunctionCode);
752 return vnfcFunctionCode;
755 public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) {
756 boolean capabilityCheckNeeded = true;
757 if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) {
758 List<AppcDataServiceConstant.ACTIONS> actionList = new ArrayList<AppcDataServiceConstant.ACTIONS>(
759 Arrays.asList(AppcDataServiceConstant.ACTIONS.values()));
760 for (AppcDataServiceConstant.ACTIONS action : actionList) {
761 if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) {
762 capabilityCheckNeeded = false;
767 return capabilityCheckNeeded;