aboutsummaryrefslogtreecommitdiffstats
path: root/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/CatalogClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/CatalogClient.java')
-rw-r--r--apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/CatalogClient.java143
1 files changed, 67 insertions, 76 deletions
diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/CatalogClient.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/CatalogClient.java
index bb0edbf..0632108 100644
--- a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/CatalogClient.java
+++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/CatalogClient.java
@@ -1,17 +1,15 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.consulextend;
@@ -32,71 +30,64 @@ import com.orbitz.consul.option.QueryOptions;
*/
public class CatalogClient {
- private static final Logger LOGGER = LoggerFactory
- .getLogger(CatalogClient.class);
-
- private static final TypeReference<HttpEntity> TYPE_SERVICES_MAP = new TypeReference<HttpEntity>() {
- };
-
-
- private static final String CATALOG_URI_8500 = "/v1/catalog";
- private static final String CATAlOG_URI_10081 = "/api/catalog/v1";
-
- private static final String GET_SERVICES_URI = "/services";
-
- private static final Http httpClient = Http.getInstance();
-
- private HttpHost targetHost = null;
- private String catalogUri = CATAlOG_URI_10081;
-
- CatalogClient(final HttpHost targetHost) {
- this.targetHost = targetHost;
- if (targetHost.getPort() == 8500) {
- catalogUri = CATALOG_URI_8500;
- }
- }
-
- /**
- * Retrieves all services for a given datacenter with
- * {@link com.orbitz.consul.option.QueryOptions}.
- *
- * GET /v1/catalog/services?dc={datacenter}
- *
- * @param catalogOptions
- * Catalog specific options to use.
- * @param queryOptions
- * The Query Options to use.
- * @return A {@link com.orbitz.consul.model.ConsulResponse} containing a map
- * of service name to list of tags.
- */
- public void getServices(CatalogOptions catalogOptions,
- QueryOptions queryOptions,
- ConsulResponseCallback<HttpEntity> callback) {
-
- // prepare access path
- // path:10081 vs 8500
- String path = targetHost.toString() + catalogUri + GET_SERVICES_URI;
-
- // params:wait,index,dc......
- String params = Http.optionsFrom(catalogOptions, queryOptions);
-
- // node meta: ns,external,internal.....
- String node_meta = ConfigUtil.getInstance().getNodeMetaQueryParam();
-
- // add params
- path = (params != null && !params.isEmpty()) ? path += "?" + params
- : path;
-
- // add node_meta
- if (node_meta != null && !node_meta.isEmpty()) {
- path = path.contains("?") ? path +"&"+ node_meta : path + "?"
- + node_meta;
- }
-
- // async watch services
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("get all services:" + path);
- }
- httpClient.asyncGetDelayHandle(path, TYPE_SERVICES_MAP, callback);
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(CatalogClient.class);
+
+ private static final TypeReference<HttpEntity> TYPE_SERVICES_MAP = new TypeReference<HttpEntity>() {};
+
+
+ private static final String CATALOG_URI_8500 = "/v1/catalog";
+ private static final String CATAlOG_URI_10081 = "/api/catalog/v1";
+
+ private static final String GET_SERVICES_URI = "/services";
+
+ private static final Http httpClient = Http.getInstance();
+
+ private HttpHost targetHost = null;
+ private String catalogUri = CATAlOG_URI_10081;
+
+ CatalogClient(final HttpHost targetHost) {
+ this.targetHost = targetHost;
+ if (targetHost.getPort() == 8500) {
+ catalogUri = CATALOG_URI_8500;
+ }
+ }
+
+ /**
+ * Retrieves all services for a given datacenter with
+ * {@link com.orbitz.consul.option.QueryOptions}.
+ *
+ * GET /v1/catalog/services?dc={datacenter}
+ *
+ * @param catalogOptions Catalog specific options to use.
+ * @param queryOptions The Query Options to use.
+ * @return A {@link com.orbitz.consul.model.ConsulResponse} containing a map of service name to
+ * list of tags.
+ */
+ public void getServices(CatalogOptions catalogOptions, QueryOptions queryOptions,
+ ConsulResponseCallback<HttpEntity> callback) {
+
+ // prepare access path
+ // path:10081 vs 8500
+ String path = targetHost.toString() + catalogUri + GET_SERVICES_URI;
+
+ // params:wait,index,dc......
+ String params = Http.optionsFrom(catalogOptions, queryOptions);
+
+ // node meta: ns,external,internal.....
+ String node_meta = ConfigUtil.getInstance().getNodeMetaQueryParam();
+
+ // add params
+ path = (params != null && !params.isEmpty()) ? path += "?" + params : path;
+
+ // add node_meta
+ if (node_meta != null && !node_meta.isEmpty()) {
+ path = path.contains("?") ? path + "&" + node_meta : path + "?" + node_meta;
+ }
+
+ // async watch services
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("get all services:" + path);
+ }
+ httpClient.asyncGetDelayHandle(path, TYPE_SERVICES_MAP, callback);
+ }
}