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=========================================================
25 package org.onap.appc.dg.netconf.impl;
27 import com.fasterxml.jackson.core.JsonProcessingException;
28 import com.fasterxml.jackson.databind.ObjectMapper;
32 import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
33 import org.onap.appc.adapter.netconf.NetconfDataAccessService;
34 import org.onap.appc.adapter.netconf.exception.DataAccessException;
35 import org.onap.appc.adapter.netconf.util.Constants;
36 import org.onap.appc.dg.netconf.NetconfDBPlugin;
37 import org.onap.appc.exceptions.APPCException;
38 import com.att.eelf.configuration.EELFLogger;
39 import com.att.eelf.configuration.EELFManager;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
42 public class NetconfDBPluginImpl implements NetconfDBPlugin {
44 private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
45 private static ObjectMapper mapper = new ObjectMapper();
47 // populated by blueprint framework
48 private NetconfDataAccessService daoService;
50 public void setDaoService(NetconfDataAccessService daoService) {
51 this.daoService = daoService;
52 this.daoService.setSchema(Constants.NETCONF_SCHEMA);
55 public NetconfDBPluginImpl() {
58 public void retrieveDSConfiguration(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
61 String fileContent = daoService.retrieveConfigFileName(params.get(Constants.CONFIGURATION_FILE_FIELD_NAME));
62 ctx.setAttribute(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
63 } catch(DataAccessException e) {
64 logger.error("Error " + e.getMessage());
65 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
69 getConnection(params, ctx);
73 public void retrieveVMDSConfiguration(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
74 logger.info("Setting entity value :" +params.get(Constants.RESOURCEKEY));
75 ctx.setAttribute("entity", params.get(Constants.RESOURCEKEY));
76 NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
78 if (!daoService.retrieveNetconfConnectionDetails(params.get(Constants.RESOURCEKEY), connectionDetails)) {
79 ctx.setAttribute("retrieveVMDSConfiguration_Result","failure");
80 logger.error("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME));
81 throw new APPCException("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
83 ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
84 ctx.setAttribute("retrieveVMDSConfiguration_Result","success");
85 } catch(APPCException e) {
86 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
88 } catch(DataAccessException | JsonProcessingException e) {
89 logger.error("Error " + e.getMessage());
90 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
91 throw new APPCException(e);
96 public void retrieveConfigFile(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
97 String fileContent = daoService.retrieveConfigFileName(params.get(Constants.CONFIGURATION_FILE_FIELD_NAME));
98 ctx.setAttribute(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
101 public void retrieveConnectionDetails(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
102 getConnection(params, ctx);
105 private void getConnection(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
106 NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
108 if (!daoService.retrieveNetconfConnectionDetails(params.get(Constants.VNF_TYPE_FIELD_NAME), connectionDetails)) {
109 logger.error("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME));
110 throw new APPCException("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
112 connectionDetails.setHost(params.get(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME));
113 ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
114 } catch(APPCException e) {
115 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
117 } catch(DataAccessException | JsonProcessingException e) {
118 logger.error("Error " + e.getMessage());
119 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
120 throw new APPCException(e);