Second part of onap rename
[appc.git] / appc-outbound / appc-network-inventory-client / provider / src / main / java / org / openecomp / appc / instar / interfaceImpl / InterfaceIpAddressImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.instar.interfaceImpl;
26
27 import java.util.HashMap;
28 import java.util.List;
29
30 import org.onap.appc.instar.interfaces.ResponseHandlerInterface;
31 import org.onap.appc.instar.interfaces.RestClientInterface;
32 import org.onap.appc.instar.interfaces.RuleHandlerInterface;
33 import org.onap.appc.instar.node.InstarClientNode;
34 import org.onap.appc.instar.utils.InstarClientConstant;
35 import org.openecomp.sdnc.config.params.data.Parameter;
36 import org.openecomp.sdnc.config.params.data.ResponseKey;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38
39 import com.att.eelf.configuration.EELFLogger;
40 import com.att.eelf.configuration.EELFManager;
41
42 public class InterfaceIpAddressImpl implements RuleHandlerInterface {
43
44         private static final EELFLogger log = EELFManager.getInstance().getLogger(InterfaceIpAddressImpl.class);
45         private  Parameter parameters;
46         private SvcLogicContext context; 
47
48         public InterfaceIpAddressImpl(Parameter params, SvcLogicContext ctx) {                  
49                 this.parameters = params;
50                 this.context = ctx;
51         }
52
53         @Override
54         public void processRule() throws Exception {
55
56                 String fn = "InterfaceIpAddressHandler.processRule";
57                 log.info(fn + "Processing rule :" + parameters.getRuleType());
58                 String operationName ;
59                 
60                 RestClientInterface restClient = null;
61                 ResponseHandlerInterface responseHandler = null;
62
63                 List<ResponseKey> responseKeyList = parameters.getResponseKeys();
64                 if(responseKeyList != null && responseKeyList.size() > 0){
65                         for(ResponseKey filterKeys : responseKeyList){                  
66                                 //response.setUniqueKeyValue(response.getUniqueKeyValue()+ context.getAttribute(InstarClientConstant.VNF_NAME));
67                                 switch(parameters.getSource()){
68                                 case InstarClientConstant.SOURCE_SYSTEM_INSTAR:                                         
69                                         restClient = new InstarRestClientImpl(createInstarRequestData(context));
70                                         responseHandler = new InstarResponseHandlerImpl(filterKeys, context );
71                                         operationName = "getIpAddressByVnf";
72                                         break;
73                                 default:
74                                         throw new Exception("No Client registered for : " + parameters.getSource());
75         
76                                 }
77                                 responseHandler.processResponse(restClient.sendRequest(operationName),parameters.getName() );
78                         }
79                 }
80                 else
81                 {
82                         throw new Exception("NO response Keys set  for : "  + parameters.getRuleType());
83                 }
84         }
85
86         private HashMap<String, String> createInstarRequestData(SvcLogicContext ctxt) {
87                 HashMap<String, String> requestParams = new HashMap<String, String>();          
88                 requestParams.put(InstarClientConstant.VNF_NAME, ctxt.getAttribute(InstarClientConstant.VNF_NAME));             
89                 return requestParams;
90         }
91 }