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.adapter.netconf.internal;
25 import javax.sql.rowset.CachedRowSet;
27 import org.openecomp.appc.adapter.netconf.ConnectionDetails;
28 import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails;
29 import org.openecomp.appc.adapter.netconf.NetconfDataAccessService;
30 import org.openecomp.appc.adapter.netconf.exception.DataAccessException;
31 import org.openecomp.appc.adapter.netconf.util.Constants;
32 import org.openecomp.appc.exceptions.APPCException;
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35 import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
37 import java.sql.SQLException;
38 import java.util.ArrayList;
41 public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
43 private static EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class);
45 public void setSchema(String schema) {
49 private String schema;
51 public void setDbLibService(DbLibService service) {dbLibService = service;}
53 private DbLibService dbLibService;
56 public String retrieveConfigFileName(String xmlID) throws DataAccessException {
57 String fileContent = "";
59 String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
60 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
61 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
63 ArrayList<String> argList = new ArrayList<>();
68 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
70 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
73 } catch (Throwable e) {
74 logger.error("Error Accessing Database " + e);
75 throw new DataAccessException(e);
82 public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) throws
84 boolean recordFound = false;
86 String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
87 "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
88 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
90 ArrayList<String> argList = new ArrayList<>();
95 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
97 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
98 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
99 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
103 } catch (SQLException e) {
104 logger.error("Error Accessing Database " + e);
105 throw new DataAccessException(e);
112 public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) throws
115 ConnectionDetails connDetails = new ConnectionDetails();
116 if(this.retrieveConnectionDetails(vnfType, connDetails))
118 connectionDetails.setHost(connDetails.getHost());
119 connectionDetails.setPort(connDetails.getPort());
120 connectionDetails.setUsername(connDetails.getUsername());
121 connectionDetails.setPassword(connDetails.getPassword());
127 public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) throws
128 DataAccessException {
130 String queryString = "INSERT INTO "+ Constants.DEVICE_INTERFACE_LOG_TABLE_NAME+"("+
131 Constants.SERVICE_INSTANCE_ID_FIELD_NAME+","+
132 Constants.REQUEST_ID_FIELD_NAME+","+
133 Constants.CREATION_DATE_FIELD_NAME+","+
134 Constants.LOG_FIELD_NAME+") ";
135 queryString += "values(?,?,?,?)";
137 ArrayList<String> argList = new ArrayList<>();
138 argList.add(instanceId);
139 argList.add(requestId);
140 argList.add(creationDate);
141 argList.add(logText);
145 dbLibService.writeData(queryString, argList, schema);
147 } catch (SQLException e) {
148 logger.error("Logging Device interaction failed - "+ queryString);
149 throw new DataAccessException(e);