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 lombok.extern.slf4j.Slf4j;
20 import org.apache.http.HttpResponse;
21 import org.apache.http.client.methods.HttpGet;
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 EngineInsQueryTool {
43 String[] msbAddrInfo = MicroServiceConfig.getMsbIpAndPort();
44 url = String.format("http://%s:%s/api/microservices/v1/services/holmes-engine-mgmt/version/v1",
45 msbAddrInfo[0], msbAddrInfo[1]);
48 public List<String> getInstanceList() throws Exception {
50 HttpGet httpGet = new HttpGet(url);
51 try (CloseableHttpClient httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT)) {
52 HttpResponse httpResponse = HttpsUtils.get(httpGet, new HashMap<>(), httpClient);
53 response = HttpsUtils.extractResponseEntity(httpResponse);
54 } catch (Exception e) {
57 httpGet.releaseConnection();
60 ServiceEntity service = GsonUtil.jsonToBean(response, ServiceEntity.class);
61 List<ServiceNode4Query> nodesList = service.getNodes();
62 List<String> ipList = new ArrayList<>();
63 for (ServiceNode4Query node : nodesList) {
64 ipList.add(node.getIp());