Change nexus values to properties
[appc.git] / app-c / appc / appc-dg / appc-dg-shared / appc-dg-ssh / src / main / java / org / openecomp / appc / dg / ssh / impl / SshDBPluginImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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  */
21
22 package org.openecomp.appc.dg.ssh.impl;
23
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26
27 import java.util.Map;
28
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.openecomp.appc.dg.ssh.SshDBPlugin;
34 import org.openecomp.appc.exceptions.APPCException;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
37 import org.openecomp.sdnc.sli.SvcLogicContext;
38
39 public class SshDBPluginImpl implements SshDBPlugin {
40
41     private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
42     private static ObjectMapper mapper = new ObjectMapper();
43
44     private SshDataAccessService dataAccessService;
45
46     public void setDataAccessService(SshDataAccessService dataAccessService) {
47         this.dataAccessService = dataAccessService;
48     }
49
50     public void retrieveConnectionDetails(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
51         SshConnectionDetails connectionDetails = new SshConnectionDetails();
52         String vnfType = ctx.getAttribute("aai.prefix")+"."+"vnf-type";
53         try {
54             if (!dataAccessService.retrieveConnectionDetails(ctx.getAttribute(vnfType), connectionDetails)) {
55                 logger.error("Missing configuration for " + params.get(vnfType));
56                 throw new APPCException("Missing configuration for " + params.get(vnfType) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
57             }
58             connectionDetails.setHost(params.get(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME));
59             ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
60         } catch(APPCException e) {
61             ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
62             throw e;
63         } catch(SshDataAccessException e) {
64             logger.error("Error " + e.getMessage());
65             ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
66             throw e;
67         } catch (JsonProcessingException e) {
68             logger.error("Error " + e.getMessage());
69             ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
70             throw new APPCException(e);
71         }
72     }
73
74 }