6c72ffa9b6a58abf4969a5f8cea1fbab57e7ea7c
[appc.git] /
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 com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import java.io.IOException;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import org.onap.appc.instar.interfaces.ResponseHandlerInterface;
34 import org.onap.appc.instar.interfaces.RestClientInterface;
35 import org.onap.appc.instar.interfaces.RuleHandlerInterface;
36 import org.onap.appc.instar.utils.InstarClientConstant;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import org.onap.sdnc.config.params.data.Parameter;
39 import org.onap.sdnc.config.params.data.ResponseKey;
40
41 public class InterfaceIpAddressImpl implements RuleHandlerInterface {
42
43     private static final EELFLogger log = EELFManager.getInstance().getLogger(InterfaceIpAddressImpl.class);
44     private Parameter parameters;
45     private SvcLogicContext context;
46
47     public InterfaceIpAddressImpl(Parameter params, SvcLogicContext ctx) {
48         this.parameters = params;
49         this.context = ctx;
50     }
51
52     @Override
53     public void processRule() throws InstarResponseException, IOException {
54
55         String fn = "InterfaceIpAddressHandler.processRule";
56         log.info(fn + "Processing rule :" + parameters.getRuleType());
57         String operationName;
58
59         RestClientInterface restClient;
60         ResponseHandlerInterface responseHandler;
61
62         List<ResponseKey> responseKeyList = parameters.getResponseKeys();
63         if (responseKeyList != null && !responseKeyList.isEmpty()) {
64             for (ResponseKey filterKeys : responseKeyList) {
65                 if (parameters.getSource().equals(InstarClientConstant.SOURCE_SYSTEM_INSTAR)) {
66                     restClient = new InstarRestClientImpl(createInstarRequestData(context));
67                     responseHandler = new InstarResponseHandlerImpl(filterKeys, context);
68                     operationName = "getIpAddressByVnf";
69
70                 } else {
71                     throw new InstarResponseException("No Client registered for : " + parameters.getSource());
72                 }
73                 responseHandler.processResponse(restClient.sendRequest(operationName), parameters.getName());
74             }
75         } else {
76             throw new InstarResponseException("NO response Keys set  for : " + parameters.getRuleType());
77         }
78     }
79
80     private Map<String, String> createInstarRequestData(SvcLogicContext ctxt) {
81         HashMap<String, String> requestParams = new HashMap<>();
82         requestParams.put(InstarClientConstant.VNF_NAME, ctxt.getAttribute(InstarClientConstant.VNF_NAME));
83         return requestParams;
84     }
85 }