2 * Copyright 2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.holmes.rulemgt.msb;
19 import java.io.IOException;
20 import lombok.extern.slf4j.Slf4j;
21 import org.apache.http.HttpResponse;
22 import org.apache.http.impl.client.CloseableHttpClient;
23 import org.jvnet.hk2.annotations.Service;
24 import org.onap.holmes.common.api.entity.ServiceEntity;
25 import org.onap.holmes.common.api.entity.ServiceNode4Query;
26 import org.onap.holmes.common.config.MicroServiceConfig;
27 import org.onap.holmes.common.utils.GsonUtil;
28 import org.onap.holmes.common.utils.HttpsUtils;
30 import javax.annotation.PostConstruct;
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
37 public class EngineIpList {
39 private String[] msbAddrInfo;
46 msbAddrInfo = MicroServiceConfig.getMsbIpAndPort();
48 port = msbAddrInfo[1];
49 url = "http://" + ip + ":" + port + "/api/microservices/v1/services/holmes-engine-mgmt/version/v1" ;
52 public List<String> getServiceCount()throws Exception{
54 CloseableHttpClient httpClient = null;
56 httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
57 HttpResponse httpResponse = HttpsUtils
58 .get(url, new HashMap<>(), httpClient);
59 response = HttpsUtils.extractResponseEntity(httpResponse);
60 } catch (Exception e) {
63 if (httpClient != null) {
66 } catch (IOException e) {
67 log.warn("Failed to close http client!");
71 ServiceEntity service = GsonUtil.jsonToBean(response, ServiceEntity.class);
72 List<ServiceNode4Query> nodesList = service.getNodes();
73 List<String> ipList = new ArrayList<>();
74 for(ServiceNode4Query node : nodesList){
75 ipList.add(node.getIp());