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.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.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
36 import org.apache.commons.lang3.StringUtils;
37 import org.openecomp.appc.instar.interfaceImpl.InstarRestClientImpl;
38 import org.openecomp.appc.instar.interfaceImpl.InterfaceIpAddressImpl;
39 import org.openecomp.appc.instar.interfaces.RestClientInterface;
40 import org.openecomp.appc.instar.interfaces.RuleHandlerInterface;
41 import org.openecomp.appc.instar.utils.InstarClientConstant;
42 import org.openecomp.sdnc.config.params.data.Parameter;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
44 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
45 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
47 public class InstarClientNode implements SvcLogicJavaPlugin
49 private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarClientNode.class);
51 public void getInstarInfo(Map<String, String> inParams, SvcLogicContext ctx)
52 throws SvcLogicException{
53 log.info("Received getInstarInfo call with params : " + inParams);
54 String responsePrefix = (String)inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX);
57 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : "";
58 String [] instarKeys = getInstarKeys(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 RuleHandlerInterface handler = null;
64 log.info("Received Context : " + ctx.getAttribute("INSTAR." + instarKey));
65 Parameter params = mapper.readValue(ctx.getAttribute(InstarClientConstant.SOURCE_SYSTEM_INSTAR + "." + instarKey), Parameter.class);
67 log.info("Processing rule Type : " + params.getRuleType());
68 switch(params.getRuleType()){
69 case InstarClientConstant.INTERFACE_IP_ADDRESS:
70 handler = new InterfaceIpAddressImpl(params, ctx);
73 throw new Exception("No Rule Defined to process :" + params.getRuleType());
75 handler.processRule();
78 log.info("responsePrefix =" + responsePrefix);
79 ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
80 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_SUCCESS);
81 ctx.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, null);
85 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_FAILURE);
86 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
87 log.error("Failed processing Instar request" + e.getMessage());
89 throw new SvcLogicException(e.getMessage());
92 private static String[] getInstarKeys(String keyString) {
93 String fn = "InstarClientNode.getInstarKeys";
94 System.out.println("Received instar Key String as :" + keyString);
96 keyString = keyString.replace("[","");
97 keyString = keyString.replace("]", "");
98 keyString = keyString.replace("\"", "");
99 if(keyString.contains(","))
101 String[] keys = keyString.split(",");
105 String[] keys = {keyString};
109 public void getInstarData(Map<String, String> inParams, SvcLogicContext ctx)
110 throws SvcLogicException{
111 log.info("Received getInstarData call with params : " + inParams);
112 String responsePrefix = (String)inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX);
115 HashMap<String, String> input = new HashMap<String, String>();
116 input.putAll(inParams);
117 RestClientInterface rcINterface = new InstarRestClientImpl(input);
118 String response = rcINterface.sendRequest(inParams.get("operationName"));
120 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : "";
121 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_SUCCESS);
122 ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, response);
127 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_FAILURE);
128 ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
129 log.error("Failed processing Instar request" + e.getMessage());
131 throw new SvcLogicException(e.getMessage());