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