2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2018 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.instar.node;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
32 import java.util.HashMap;
34 import org.apache.commons.lang3.StringUtils;
35 import org.onap.appc.aai.interfaceImpl.AaiInterfaceRulesHandler;
36 import org.onap.appc.aai.utils.AaiClientConstant;
37 import org.onap.appc.instar.interfaceImpl.InstarRestClientImpl;
38 import org.onap.appc.instar.interfaceImpl.InterfaceIpAddressImpl;
39 import org.onap.appc.instar.interfaces.RestClientInterface;
40 import org.onap.appc.instar.interfaces.RuleHandlerInterface;
41 import org.onap.appc.instar.utils.InstarClientConstant;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
44 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
45 import org.onap.sdnc.config.params.data.Parameter;
47 public class InstarClientNode implements SvcLogicJavaPlugin {
49 private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarClientNode.class);
52 public void getInstarInfo(Map<String, String> inParams, SvcLogicContext ctx)
53 throws SvcLogicException {
54 log.info("Received getInstarInfo call with params : " + inParams);
55 String responsePrefix = inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX);
57 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : "";
58 String[] instarKeys = getKeys(inParams.get(InstarClientConstant.INSTAR_KEYS));
59 for (String instarKey : instarKeys) {
60 log.info("Processing Key : " + instarKey);
61 log.info("Searching key for : " + "INSTAR." + instarKey);
62 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
63 log.info("Received Context : " + ctx.getAttribute("INSTAR." + instarKey));
64 Parameter params = mapper
65 .readValue(ctx.getAttribute(InstarClientConstant.SOURCE_SYSTEM_INSTAR + "." + instarKey),
67 RuleHandlerInterface handler;
68 log.info("Processing rule Type : " + params.getRuleType());
69 if (params.getRuleType().equals(InstarClientConstant.INTERFACE_IP_ADDRESS)) {
70 handler = createHandler(params, ctx);
72 throw new SvcLogicException("No Rule Defined to process :" + params.getRuleType());
74 handler.processRule();
76 log.info("responsePrefix =" + responsePrefix);
77 log.info("instar key values =" + ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
78 ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES,
79 ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
80 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS,
81 InstarClientConstant.OUTPUT_STATUS_SUCCESS);
82 log.info(ctx.getAttribute("TEST." + InstarClientConstant.OUTPUT_PARAM_STATUS));
83 ctx.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, null);
84 } catch (Exception e) {
85 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS,
86 InstarClientConstant.OUTPUT_STATUS_FAILURE);
87 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
88 log.error("Failed processing Instar request", e);
89 throw new SvcLogicException(e.getMessage());
93 private static String[] getKeys(String keyString) {
94 log.error("Received Key String as :" + keyString);
95 String key = keyString
99 if (key.contains(",")) {
100 return key.split(",");
102 return new String[]{key};
106 public void getInstarData(Map<String, String> inParams, SvcLogicContext ctx)
107 throws SvcLogicException {
108 log.info("Received getInstarData call with params : " + inParams);
109 String responsePrefix = inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX);
111 HashMap<String, String> input = new HashMap<>();
112 input.putAll(inParams);
113 RestClientInterface rcINterface = createRestClientInterface(input);
114 String response = rcINterface.sendRequest(inParams.get("operationName"));
115 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : "";
116 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS,
117 InstarClientConstant.OUTPUT_STATUS_SUCCESS);
118 ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, response);
119 } catch (Exception e) {
120 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS,
121 InstarClientConstant.OUTPUT_STATUS_FAILURE);
122 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
123 log.error("Failed processing Instar request", e);
124 throw new SvcLogicException(e.getMessage());
128 public void getAaiInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
129 log.info("Received getAaiInfo call with params : " + inParams);
130 String responsePrefix = inParams.get(AaiClientConstant.INPUT_PARAM_RESPONSE_PRIFIX);
132 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : "";
133 String[] aaiKeys = getKeys(inParams.get(AaiClientConstant.AAI_KEYS));
134 for (String aaiKey : aaiKeys) {
135 log.info("Processing Key : " + aaiKey);
136 log.info("Searching key for : " + "AAI." + aaiKey);
137 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
138 log.info("Received Context : " + ctx.getAttribute("AAI." + aaiKey));
139 Parameter params = mapper.readValue(
140 ctx.getAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + aaiKey), Parameter.class);
141 log.info("Processing rule Type : " + params.getRuleType());
142 RuleHandlerInterface handler = new AaiInterfaceRulesHandler(params, ctx);
143 handler.processRule();
145 log.info("responsePrefix =" + responsePrefix);
146 ctx.setAttribute(responsePrefix + AaiClientConstant.AAI_KEY_VALUES,
147 ctx.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
148 ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_STATUS,
149 AaiClientConstant.OUTPUT_STATUS_SUCCESS);
150 ctx.setAttribute(AaiClientConstant.AAI_KEY_VALUES, null);
151 } catch (Exception e) {
152 ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_STATUS,
153 InstarClientConstant.OUTPUT_STATUS_FAILURE);
154 ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
155 log.error("Failed processing AAI data", e);
156 throw new SvcLogicException(e.getMessage());
160 protected RuleHandlerInterface createHandler(Parameter params, SvcLogicContext ctx) {
161 return new InterfaceIpAddressImpl(params, ctx);
164 protected RestClientInterface createRestClientInterface(Map<String, String> input) {
165 return new InstarRestClientImpl(input);