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.ssh.sshd;
24 import javax.sql.rowset.CachedRowSet;
26 import org.openecomp.appc.adapter.ssh.Constants;
27 import org.openecomp.appc.adapter.ssh.SshConnectionDetails;
28 import org.openecomp.appc.adapter.ssh.SshDataAccessException;
29 import org.openecomp.appc.adapter.ssh.SshDataAccessService;
30 import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
32 import java.sql.SQLException;
33 import java.util.ArrayList;
35 public class SshdDataAccessService implements SshDataAccessService {
37 private String schema = Constants.NETCONF_SCHEMA;
38 private DbLibService dbLibService;
41 public void setSchema(String schema) {
46 public void setDbLibService(DbLibService dbLibService) {
47 this.dbLibService = dbLibService;
51 public boolean retrieveConnectionDetails(String vnfType, SshConnectionDetails connectionDetails) throws SshDataAccessException {
53 boolean recordFound = false;
55 String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
56 "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
57 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
59 ArrayList<String> argList = new ArrayList<>();
64 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
67 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
68 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
69 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
72 } catch (SQLException e) {
73 throw new SshDataAccessException(e);
80 public String retrieveConfigFileName(String xmlID) throws SshDataAccessException {
83 String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
84 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
85 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
87 ArrayList<String> argList = new ArrayList<>();
92 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
93 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
95 } catch (SQLException e) {
96 throw new SshDataAccessException(e);