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.dg.ssh.impl;
24 import com.att.eelf.i18n.EELFResourceManager;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
30 import org.openecomp.appc.adapter.ssh.Constants;
31 import org.openecomp.appc.adapter.ssh.SshConnectionDetails;
32 import org.openecomp.appc.adapter.ssh.SshDataAccessException;
33 import org.openecomp.appc.adapter.ssh.SshDataAccessService;
34 import org.openecomp.appc.dg.ssh.SshDBPlugin;
35 import org.openecomp.appc.exceptions.APPCException;
36 import org.openecomp.appc.i18n.Msg;
38 import com.att.eelf.configuration.EELFLogger;
39 import com.att.eelf.configuration.EELFManager;
40 import org.openecomp.sdnc.sli.SvcLogicContext;
42 public class SshDBPluginImpl implements SshDBPlugin {
44 private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
45 private static ObjectMapper mapper = new ObjectMapper();
47 private SshDataAccessService dataAccessService;
49 public void setDataAccessService(SshDataAccessService dataAccessService) {
50 this.dataAccessService = dataAccessService;
53 public void retrieveConnectionDetails(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
54 SshConnectionDetails connectionDetails = new SshConnectionDetails();
55 //String vnfType = ctx.getAttribute("aai.prefix")+"."+"vnf-type";
56 String vnfType = params.get("vnf-type");
58 if (!dataAccessService.retrieveConnectionDetails(vnfType, connectionDetails)) {
59 logger.error("Missing connection details for VNF type: " + vnfType);
60 throw new APPCException("Missing configuration for " + vnfType + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
62 connectionDetails.setHost(params.get(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME));
63 ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
64 } catch(APPCException e) {
65 String msg = EELFResourceManager.format(Msg.APPC_EXCEPTION, vnfType, e.getMessage());
67 ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg);
69 } catch(SshDataAccessException e) {
70 String msg = EELFResourceManager.format(Msg.SSH_DATA_EXCEPTION, e.getMessage());
72 ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
74 } catch (JsonProcessingException e) {
75 String msg = EELFResourceManager.format(Msg.JSON_PROCESSING_EXCEPTION, e.getMessage());
77 ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
78 throw new APPCException(e);