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.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
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;
39 public class SshDBPluginImpl implements SshDBPlugin {
41 private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
42 private static ObjectMapper mapper = new ObjectMapper();
44 private SshDataAccessService dataAccessService;
46 public void setDataAccessService(SshDataAccessService dataAccessService) {
47 this.dataAccessService = dataAccessService;
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";
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);
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());
63 } catch(SshDataAccessException e) {
64 logger.error("Error " + e.getMessage());
65 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
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);