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