2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.dg.netconf.impl;
26 import com.fasterxml.jackson.core.JsonProcessingException;
27 import com.fasterxml.jackson.databind.ObjectMapper;
31 import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
32 import org.onap.appc.adapter.netconf.NetconfDataAccessService;
33 import org.onap.appc.adapter.netconf.exception.DataAccessException;
34 import org.onap.appc.adapter.netconf.util.Constants;
35 import org.onap.appc.dg.netconf.NetconfDBPlugin;
36 import org.onap.appc.exceptions.APPCException;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
41 public class NetconfDBPluginImpl implements NetconfDBPlugin {
43 private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
44 private static ObjectMapper mapper = new ObjectMapper();
46 // populated by blueprint framework
47 private NetconfDataAccessService daoService;
49 public void setDaoService(NetconfDataAccessService daoService) {
50 this.daoService = daoService;
51 this.daoService.setSchema(Constants.NETCONF_SCHEMA);
54 public NetconfDBPluginImpl() {
57 public void retrieveDSConfiguration(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
60 String fileContent = daoService.retrieveConfigFileName(params.get(Constants.CONFIGURATION_FILE_FIELD_NAME));
61 ctx.setAttribute(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
62 } catch(DataAccessException e) {
63 logger.error("Error " + e.getMessage());
64 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
68 getConnection(params, ctx);
72 public void retrieveVMDSConfiguration(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
73 logger.info("Setting entity value :" +params.get(Constants.RESOURCEKEY));
74 ctx.setAttribute("entity", params.get(Constants.RESOURCEKEY));
75 NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
77 if (!daoService.retrieveNetconfConnectionDetails(params.get(Constants.RESOURCEKEY), connectionDetails)) {
78 ctx.setAttribute("retrieveVMDSConfiguration_Result","failure");
79 logger.error("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME));
80 throw new APPCException("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
82 ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
83 ctx.setAttribute("retrieveVMDSConfiguration_Result","success");
84 } catch(APPCException e) {
85 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
87 } catch(DataAccessException | JsonProcessingException e) {
88 logger.error("Error " + e.getMessage());
89 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
90 throw new APPCException(e);
95 public void retrieveConfigFile(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
96 String fileContent = daoService.retrieveConfigFileName(params.get(Constants.CONFIGURATION_FILE_FIELD_NAME));
97 ctx.setAttribute(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
100 public void retrieveConnectionDetails(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
101 getConnection(params, ctx);
104 private void getConnection(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
105 NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
107 if (!daoService.retrieveNetconfConnectionDetails(params.get(Constants.VNF_TYPE_FIELD_NAME), connectionDetails)) {
108 logger.error("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME));
109 throw new APPCException("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
111 connectionDetails.setHost(params.get(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME));
112 ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
113 } catch(APPCException e) {
114 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
116 } catch(DataAccessException | JsonProcessingException e) {
117 logger.error("Error " + e.getMessage());
118 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
119 throw new APPCException(e);