2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
 
   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=========================================================
 
  22 package org.openecomp.appc.dg.netconf.impl;
 
  24 import com.fasterxml.jackson.core.JsonProcessingException;
 
  25 import com.fasterxml.jackson.databind.ObjectMapper;
 
  29 import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails;
 
  30 import org.openecomp.appc.adapter.netconf.NetconfDataAccessService;
 
  31 import org.openecomp.appc.adapter.netconf.exception.DataAccessException;
 
  32 import org.openecomp.appc.adapter.netconf.util.Constants;
 
  33 import org.openecomp.appc.dg.netconf.NetconfDBPlugin;
 
  34 import org.openecomp.appc.exceptions.APPCException;
 
  35 import com.att.eelf.configuration.EELFLogger;
 
  36 import com.att.eelf.configuration.EELFManager;
 
  37 import org.openecomp.sdnc.sli.SvcLogicContext;
 
  39 public class NetconfDBPluginImpl implements NetconfDBPlugin {
 
  41     private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
 
  42     private static ObjectMapper mapper = new ObjectMapper();
 
  44     // populated by blueprint framework
 
  45     private NetconfDataAccessService daoService;
 
  47     public void setDaoService(NetconfDataAccessService daoService) {
 
  48         this.daoService = daoService;
 
  49         this.daoService.setSchema(Constants.NETCONF_SCHEMA);
 
  52     public NetconfDBPluginImpl() {
 
  55     public void retrieveDSConfiguration(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
 
  58             String fileContent = daoService.retrieveConfigFileName(params.get(Constants.CONFIGURATION_FILE_FIELD_NAME));
 
  59             ctx.setAttribute(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
 
  60         } catch(DataAccessException e) {
 
  61             logger.error("Error " + e.getMessage());
 
  62             ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
 
  66         getConnection(params, ctx);
 
  70     public void retrieveVMDSConfiguration(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
 
  71         logger.info("Setting entity value :" +params.get(Constants.RESOURCEKEY));
 
  72         ctx.setAttribute("entity", params.get(Constants.RESOURCEKEY));
 
  73         NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
 
  75             if (!daoService.retrieveNetconfConnectionDetails(params.get(Constants.RESOURCEKEY), connectionDetails)) {
 
  76                 ctx.setAttribute("retrieveVMDSConfiguration_Result","failure");
 
  77                 logger.error("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME));
 
  78                 throw new APPCException("Missing configuration for " + params.get(Constants.VNF_TYPE_FIELD_NAME) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
 
  80             //            fileContent = dsImpl.retrieveConfigFileName(params.get(Constants.CONFIGURATION_FILE_FIELD_NAME));
 
  81             //            ctx.setAttribute(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
 
  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);