2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.adapter.ssh.sshd;
27 import javax.sql.rowset.CachedRowSet;
29 import org.openecomp.appc.adapter.ssh.Constants;
30 import org.openecomp.appc.adapter.ssh.SshConnectionDetails;
31 import org.openecomp.appc.adapter.ssh.SshDataAccessException;
32 import org.openecomp.appc.adapter.ssh.SshDataAccessService;
33 import org.onap.ccsdk.sli.core.dblib.DbLibService;
35 import java.sql.SQLException;
36 import java.util.ArrayList;
38 public class SshdDataAccessService implements SshDataAccessService {
40 private String schema = Constants.NETCONF_SCHEMA;
41 private DbLibService dbLibService;
44 public void setSchema(String schema) {
49 public void setDbLibService(DbLibService dbLibService) {
50 this.dbLibService = dbLibService;
54 public boolean retrieveConnectionDetails(String vnfType, SshConnectionDetails connectionDetails) throws SshDataAccessException {
56 boolean recordFound = false;
58 String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
59 "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
60 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
62 ArrayList<String> argList = new ArrayList<>();
67 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
70 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
71 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
72 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
75 } catch (SQLException e) {
76 throw new SshDataAccessException(e);
83 public String retrieveConfigFileName(String xmlID) throws SshDataAccessException {
86 String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
87 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
88 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
90 ArrayList<String> argList = new ArrayList<>();
95 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
96 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
98 } catch (SQLException e) {
99 throw new SshDataAccessException(e);