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.onap.appc.instar.node;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
32 import java.util.HashMap;
34 import org.apache.commons.lang3.StringUtils;
35 import org.onap.appc.instar.interfaceImpl.InstarRestClientImpl;
36 import org.onap.appc.instar.interfaceImpl.InterfaceIpAddressImpl;
37 import org.onap.appc.instar.interfaces.RestClientInterface;
38 import org.onap.appc.instar.interfaces.RuleHandlerInterface;
39 import org.onap.appc.instar.utils.InstarClientConstant;
40 import org.onap.sdnc.config.params.data.Parameter;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
45 public class InstarClientNode implements SvcLogicJavaPlugin
47 private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarClientNode.class);
49 public void getInstarInfo(Map<String, String> inParams, SvcLogicContext ctx)
50 throws SvcLogicException{
51 log.info("Received getInstarInfo call with params : " + inParams);
52 String responsePrefix = (String)inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX);
55 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : "";
56 String [] instarKeys = getInstarKeys(inParams.get(InstarClientConstant.INSTAR_KEYS));
57 for (String instarKey : instarKeys){
58 log.info("Processing Key : " + instarKey);
59 log.info("Searching key for : " + "INSTAR." + instarKey);
60 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
61 RuleHandlerInterface handler = null;
62 log.info("Received Context : " + ctx.getAttribute("INSTAR." + instarKey));
63 Parameter params = mapper.readValue(ctx.getAttribute(InstarClientConstant.SOURCE_SYSTEM_INSTAR + "." + instarKey), Parameter.class);
65 log.info("Processing rule Type : " + params.getRuleType());
66 switch(params.getRuleType()){
67 case InstarClientConstant.INTERFACE_IP_ADDRESS:
68 handler = new InterfaceIpAddressImpl(params, ctx);
71 throw new Exception("No Rule Defined to process :" + params.getRuleType());
73 handler.processRule();
76 log.info("responsePrefix =" + responsePrefix);
77 ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
78 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_SUCCESS);
79 ctx.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, null);
83 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_FAILURE);
84 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
85 log.error("Failed processing Instar request" + e.getMessage());
87 throw new SvcLogicException(e.getMessage());
90 private static String[] getInstarKeys(String keyString) {
91 String fn = "InstarClientNode.getInstarKeys";
92 System.out.println("Received instar Key String as :" + keyString);
94 keyString = keyString.replace("[","");
95 keyString = keyString.replace("]", "");
96 keyString = keyString.replace("\"", "");
97 if(keyString.contains(","))
99 String[] keys = keyString.split(",");
103 String[] keys = {keyString};
107 public void getInstarData(Map<String, String> inParams, SvcLogicContext ctx)
108 throws SvcLogicException{
109 log.info("Received getInstarData call with params : " + inParams);
110 String responsePrefix = (String)inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX);
113 HashMap<String, String> input = new HashMap<String, String>();
114 input.putAll(inParams);
115 RestClientInterface rcINterface = new InstarRestClientImpl(input);
116 String response = rcINterface.sendRequest(inParams.get("operationName"));
118 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : "";
119 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_SUCCESS);
120 ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, response);
125 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_FAILURE);
126 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
127 log.error("Failed processing Instar request" + e.getMessage());
129 throw new SvcLogicException(e.getMessage());