2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.dg.netconf.impl;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
30 import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails;
31 import org.openecomp.appc.adapter.netconf.NetconfDataAccessService;
32 import org.openecomp.appc.adapter.netconf.exception.DataAccessException;
33 import org.openecomp.appc.adapter.netconf.util.Constants;
34 import org.openecomp.appc.dg.netconf.NetconfDBPlugin;
35 import org.openecomp.appc.exceptions.APPCException;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
38 import org.openecomp.sdnc.sli.SvcLogicContext;
40 public class NetconfDBPluginImpl implements NetconfDBPlugin {
42 private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
43 private static ObjectMapper mapper = new ObjectMapper();
45 // populated by blueprint framework
46 private NetconfDataAccessService daoService;
48 public void setDaoService(NetconfDataAccessService daoService) {
49 this.daoService = daoService;
50 this.daoService.setSchema(Constants.NETCONF_SCHEMA);
53 public NetconfDBPluginImpl() {
56 public void retrieveDSConfiguration(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
59 String fileContent = daoService.retrieveConfigFileName(params.get(Constants.CONFIGURATION_FILE_FIELD_NAME));
60 ctx.setAttribute(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
61 } catch(DataAccessException e) {
62 logger.error("Error " + e.getMessage());
63 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
67 getConnection(params, ctx);
71 public void retrieveVMDSConfiguration(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
72 logger.info("Setting entity value :" +params.get(Constants.RESOURCEKEY));
73 ctx.setAttribute("entity", params.get(Constants.RESOURCEKEY));
74 NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
76 if (!daoService.retrieveNetconfConnectionDetails(params.get(Constants.RESOURCEKEY), connectionDetails)) {
77 ctx.setAttribute("retrieveVMDSConfiguration_Result","failure");
78 logger.error("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME));
79 throw new APPCException("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
81 ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
82 ctx.setAttribute("retrieveVMDSConfiguration_Result","success");
83 } catch(APPCException e) {
84 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
86 } catch(DataAccessException | JsonProcessingException e) {
87 logger.error("Error " + e.getMessage());
88 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
89 throw new APPCException(e);
94 public void retrieveConfigFile(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
95 String fileContent = daoService.retrieveConfigFileName(params.get(Constants.CONFIGURATION_FILE_FIELD_NAME));
96 ctx.setAttribute(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
99 public void retrieveConnectionDetails(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
100 getConnection(params, ctx);
103 private void getConnection(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
104 NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
106 if (!daoService.retrieveNetconfConnectionDetails(params.get(Constants.VNF_TYPE_FIELD_NAME), connectionDetails)) {
107 logger.error("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME));
108 throw new APPCException("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
110 connectionDetails.setHost(params.get(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME));
111 ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
112 } catch(APPCException e) {
113 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
115 } catch(DataAccessException | JsonProcessingException e) {
116 logger.error("Error " + e.getMessage());
117 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
118 throw new APPCException(e);