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.ssh.sshd;
25 import javax.sql.rowset.CachedRowSet;
27 import org.openecomp.appc.adapter.ssh.Constants;
28 import org.openecomp.appc.adapter.ssh.SshConnectionDetails;
29 import org.openecomp.appc.adapter.ssh.SshDataAccessException;
30 import org.openecomp.appc.adapter.ssh.SshDataAccessService;
31 import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
33 import java.sql.SQLException;
34 import java.util.ArrayList;
36 public class SshdDataAccessService implements SshDataAccessService {
38 private String schema = Constants.NETCONF_SCHEMA;
39 private DbLibService dbLibService;
42 public void setSchema(String schema) {
47 public void setDbLibService(DbLibService dbLibService) {
48 this.dbLibService = dbLibService;
52 public boolean retrieveConnectionDetails(String vnfType, SshConnectionDetails connectionDetails) throws SshDataAccessException {
54 boolean recordFound = false;
56 String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
57 "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
58 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
60 ArrayList<String> argList = new ArrayList<>();
65 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
68 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
69 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
70 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
73 } catch (SQLException e) {
74 throw new SshDataAccessException(e);
81 public String retrieveConfigFileName(String xmlID) throws SshDataAccessException {
84 String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
85 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
86 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
88 ArrayList<String> argList = new ArrayList<>();
93 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
94 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
96 } catch (SQLException e) {
97 throw new SshDataAccessException(e);