2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.ssh.sshd;
26 import javax.sql.rowset.CachedRowSet;
28 import org.onap.appc.adapter.ssh.Constants;
29 import org.onap.appc.adapter.ssh.SshConnectionDetails;
30 import org.onap.appc.adapter.ssh.SshDataAccessException;
31 import org.onap.appc.adapter.ssh.SshDataAccessService;
32 import org.onap.ccsdk.sli.core.dblib.DbLibService;
34 import java.sql.SQLException;
35 import java.util.ArrayList;
37 public class SshdDataAccessService implements SshDataAccessService {
39 private String schema = Constants.NETCONF_SCHEMA;
40 private DbLibService dbLibService;
43 public void setSchema(String schema) {
47 public String getSchema() {
52 public void setDbLibService(DbLibService dbLibService) {
53 this.dbLibService = dbLibService;
56 public DbLibService getDbLibService() {
57 return this.dbLibService;
61 public boolean retrieveConnectionDetails(String vnfType, SshConnectionDetails connectionDetails) throws SshDataAccessException {
63 boolean recordFound = false;
65 String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
66 "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
67 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
69 ArrayList<String> argList = new ArrayList<>();
74 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
77 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
78 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
79 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
82 } catch (SQLException e) {
83 throw new SshDataAccessException(e);
90 public String retrieveConfigFileName(String xmlID) throws SshDataAccessException {
93 String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
94 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
95 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
97 ArrayList<String> argList = new ArrayList<>();
102 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
103 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
105 } catch (SQLException e) {
106 throw new SshDataAccessException(e);