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.client.methods.HttpGet;
23 import org.apache.http.impl.client.CloseableHttpClient;
24 import org.jvnet.hk2.annotations.Service;
25 import org.onap.holmes.common.api.entity.ServiceEntity;
26 import org.onap.holmes.common.api.entity.ServiceNode4Query;
27 import org.onap.holmes.common.config.MicroServiceConfig;
28 import org.onap.holmes.common.utils.GsonUtil;
29 import org.onap.holmes.common.utils.HttpsUtils;
31 import javax.annotation.PostConstruct;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
38 public class EngineIpList {
40 private String[] msbAddrInfo;
47 msbAddrInfo = MicroServiceConfig.getMsbIpAndPort();
49 port = msbAddrInfo[1];
50 url = "http://" + ip + ":" + port + "/api/microservices/v1/services/holmes-engine-mgmt/version/v1" ;
53 public List<String> getServiceCount()throws Exception{
55 CloseableHttpClient httpClient = null;
56 HttpGet httpGet = new HttpGet(url);
58 httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
59 HttpResponse httpResponse = HttpsUtils
60 .get(httpGet, new HashMap<>(), httpClient);
61 response = HttpsUtils.extractResponseEntity(httpResponse);
62 } catch (Exception e) {
65 httpGet.releaseConnection();
66 if (httpClient != null) {
69 } catch (IOException e) {
70 log.warn("Failed to close http client!");
74 ServiceEntity service = GsonUtil.jsonToBean(response, ServiceEntity.class);
75 List<ServiceNode4Query> nodesList = service.getNodes();
76 List<String> ipList = new ArrayList<>();
77 for(ServiceNode4Query node : nodesList){
78 ipList.add(node.getIp());