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.adapter.netconf.internal;
24 import javax.sql.rowset.CachedRowSet;
26 import org.openecomp.appc.adapter.netconf.ConnectionDetails;
27 import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails;
28 import org.openecomp.appc.adapter.netconf.NetconfDataAccessService;
29 import org.openecomp.appc.adapter.netconf.exception.DataAccessException;
30 import org.openecomp.appc.adapter.netconf.util.Constants;
31 import org.openecomp.appc.exceptions.APPCException;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
36 import java.sql.SQLException;
37 import java.util.ArrayList;
40 public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
42 private static EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class);
44 public void setSchema(String schema) {
48 private String schema;
50 public void setDbLibService(DbLibService service) {dbLibService = service;}
52 private DbLibService dbLibService;
55 public String retrieveConfigFileName(String xmlID) throws DataAccessException {
56 String fileContent = "";
58 String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
59 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
60 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
62 ArrayList<String> argList = new ArrayList<>();
67 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
69 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
72 } catch (Throwable e) {
73 logger.error("Error Accessing Database " + e);
74 throw new DataAccessException(e);
81 public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) throws
83 boolean recordFound = false;
85 String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
86 "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
87 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
89 ArrayList<String> argList = new ArrayList<>();
94 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
96 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
97 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
98 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
102 } catch (SQLException e) {
103 logger.error("Error Accessing Database " + e);
104 throw new DataAccessException(e);
111 public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) throws
114 ConnectionDetails connDetails = new ConnectionDetails();
115 if(this.retrieveConnectionDetails(vnfType, connDetails))
117 connectionDetails.setHost(connDetails.getHost());
118 connectionDetails.setPort(connDetails.getPort());
119 connectionDetails.setUsername(connDetails.getUsername());
120 connectionDetails.setPassword(connDetails.getPassword());
126 public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) throws
127 DataAccessException {
129 String queryString = "INSERT INTO "+ Constants.DEVICE_INTERFACE_LOG_TABLE_NAME+"("+
130 Constants.SERVICE_INSTANCE_ID_FIELD_NAME+","+
131 Constants.REQUEST_ID_FIELD_NAME+","+
132 Constants.CREATION_DATE_FIELD_NAME+","+
133 Constants.LOG_FIELD_NAME+") ";
134 queryString += "values(?,?,?,?)";
136 ArrayList<String> argList = new ArrayList<>();
137 argList.add(instanceId);
138 argList.add(requestId);
139 argList.add(creationDate);
140 argList.add(logText);
144 dbLibService.writeData(queryString, argList, schema);
146 } catch (SQLException e) {
147 logger.error("Logging Device interaction failed - "+ queryString);
148 throw new DataAccessException(e);