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