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;
21 import lombok.extern.slf4j.Slf4j;
22 import org.apache.http.HttpResponse;
23 import org.apache.http.client.methods.HttpGet;
24 import org.apache.http.impl.client.CloseableHttpClient;
25 import org.jvnet.hk2.annotations.Service;
26 import org.onap.holmes.common.api.entity.ServiceEntity;
27 import org.onap.holmes.common.api.entity.ServiceNode4Query;
28 import org.onap.holmes.common.config.MicroServiceConfig;
29 import org.onap.holmes.common.utils.GsonUtil;
30 import org.onap.holmes.common.utils.HttpsUtils;
32 import javax.annotation.PostConstruct;
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.List;
39 public class EngineInsQueryTool {
45 String[] msbAddrInfo = MicroServiceConfig.getMsbIpAndPort();
46 url = String.format("http://%s:%s/api/microservices/v1/services/holmes-engine-mgmt/version/v1",
47 msbAddrInfo[0], msbAddrInfo[1]);
50 public List<String> getInstanceList() throws Exception {
52 HttpGet httpGet = new HttpGet(url);
53 try (CloseableHttpClient httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT)) {
54 HttpResponse httpResponse = HttpsUtils.get(httpGet, new HashMap<>(), httpClient);
55 response = HttpsUtils.extractResponseEntity(httpResponse);
56 } catch (Exception e) {
59 httpGet.releaseConnection();
62 ServiceEntity service = GsonUtil.jsonToBean(response, ServiceEntity.class);
63 List<ServiceNode4Query> nodesList = service.getNodes();
64 List<String> ipList = new ArrayList<>();
65 for (ServiceNode4Query node : nodesList) {
66 ipList.add(node.getIp());