[OAP Server][Cluster Plugin] Provide consul cluster plugin (#2036)
* Provide consul cluster plugin.
* Change log and application config file.
* Add consul's config item into the docker's application.yml.
* Fixed bug.
* Add consul description into readme.
* Add okhttp component license.
diff --git a/CHANGES.md b/CHANGES.md
index 990205e..51f2329 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -37,6 +37,7 @@
- Support Zipkin format again.
- Support init mode.
- Support namespace in Zookeeper cluster management.
+- Support consul plugin in cluster module.
- OAL generate tool has been integrated into main repo, in the maven `compile` stage.
- Optimize trace paging query.
- Fix trace query don't use fuzzy query in ElasticSearch storage.
@@ -46,7 +47,6 @@
- Fix `Remote clients selector error: / by zero `.
- Fix segment TTL is not working.
-
#### UI
- Support service throughput(cpm), successful rate(sla), avg response time and p99/p95/p90/p75/p50 response time.
- Fix TopN endpoint link doesn't work right.
@@ -59,7 +59,6 @@
- Update user wall and powered-by page.
- Add RocketBot UI project link in document.
-
All issues and pull requests are [here](https://github.com/apache/incubator-skywalking/milestone/31?closed=1)
6.0.0-alpha
diff --git a/apm-dist/release-docs/LICENSE b/apm-dist/release-docs/LICENSE
index 410208c..78f03f8 100644
--- a/apm-dist/release-docs/LICENSE
+++ b/apm-dist/release-docs/LICENSE
@@ -304,6 +304,8 @@
kubernetes-client 2.0.0: https://github.com/kubernetes-client/java, Apache 2.0
proto files from istio/istio: https://github.com/istio/istio Apache 2.0
proto files from istio/api: https://github.com/istio/api Apache 2.0
+ consul-client 1.2.6: https://github.com/rickfast/consul-client, Apache 2.0
+ okhttp 3.9.0: https://github.com/square/okhttp, Apache 2.0
========================================================================
MIT licenses
diff --git a/apm-dist/release-docs/licenses/LICENSE-consul-client.txt b/apm-dist/release-docs/licenses/LICENSE-consul-client.txt
new file mode 100644
index 0000000..51a1264
--- /dev/null
+++ b/apm-dist/release-docs/licenses/LICENSE-consul-client.txt
@@ -0,0 +1,13 @@
+Copyright 2014 Orbitz
+
+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
+
+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.
\ No newline at end of file
diff --git a/apm-dist/release-docs/licenses/LICENSE-okhttp.txt b/apm-dist/release-docs/licenses/LICENSE-okhttp.txt
new file mode 100644
index 0000000..7a4a3ea
--- /dev/null
+++ b/apm-dist/release-docs/licenses/LICENSE-okhttp.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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
+
+ 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.
\ No newline at end of file
diff --git a/docker/config/application.yml b/docker/config/application.yml
index 5743d09..dbdabdc 100644
--- a/docker/config/application.yml
+++ b/docker/config/application.yml
@@ -19,6 +19,7 @@
# Please check your ZooKeeper is 3.5+, However, it is also compatible with ZooKeeper 3.4.x. Replace the ZooKeeper 3.5+
# library the oap-libs folder with your ZooKeeper 3.4.x library.
# zookeeper:
+# nameSpace: ${SW_NAMESPACE:""}
# hostPort: ${SW_CLUSTER_ZK_HOST_PORT:localhost:2181}
# #Retry Policy
# baseSleepTimeMs: ${SW_CLUSTER_ZK_SLEEP_TIME:1000} # initial amount of time to wait between retries
@@ -28,6 +29,10 @@
# namespace: ${SW_CLUSTER_K8S_NAMESPACE:default}
# labelSelector: ${SW_CLUSTER_K8S_LABEL:app=collector,release=skywalking}
# uidEnvName: ${SW_CLUSTER_K8S_UID:SKYWALKING_COLLECTOR_UID}
+# consul:
+# serviceName: ${SW_SERVICE_NAME:"SkyWalking_OAP_Cluster"}
+# Consul cluster nodes, example: 10.0.0.1:8500,10.0.0.2:8500,10.0.0.3:8500
+# hostPort: ${SW_CLUSTER_CONSUL_HOST_PORT:localhost:8500}
core:
default:
restHost: ${SW_CORE_REST_HOST:0.0.0.0}
diff --git a/docs/en/setup/backend/backend-cluster.md b/docs/en/setup/backend/backend-cluster.md
index 2fcb5c9..b811f0a 100644
--- a/docs/en/setup/backend/backend-cluster.md
+++ b/docs/en/setup/backend/backend-cluster.md
@@ -19,7 +19,8 @@
```yaml
cluster:
zookeeper:
- hostPort: localhost:2181
+ nameSpace: ${SW_NAMESPACE:""}
+ hostPort: ${SW_CLUSTER_ZK_HOST_PORT:localhost:2181}
# Retry Policy
baseSleepTimeMs: 1000 # initial amount of time to wait between retries
maxRetries: 3 # max number of times to retry
@@ -41,3 +42,16 @@
labelSelector: app=collector,release=skywalking
uidEnvName: SKYWALKING_COLLECTOR_UID
```
+
+## Consul
+Now, consul is becoming a famous system, many of companies and developers using consul to be
+their service discovery solution. Set the **cluster** module's implementor to **consul** in
+the yml to active.
+
+```yaml
+cluster:
+ consul:
+ serviceName: ${SW_SERVICE_NAME:"SkyWalking_OAP_Cluster"}
+ # Consul cluster nodes, example: 10.0.0.1:8500,10.0.0.2:8500,10.0.0.3:8500
+ hostPort: ${SW_CLUSTER_CONSUL_HOST_PORT:localhost:8500}
+```
\ No newline at end of file
diff --git a/oap-server/pom.xml b/oap-server/pom.xml
index e890e24..f00eb67 100644
--- a/oap-server/pom.xml
+++ b/oap-server/pom.xml
@@ -66,6 +66,7 @@
<hikaricp.version>3.1.0</hikaricp.version>
<zipkin.version>2.9.1</zipkin.version>
<caffeine.version>2.6.2</caffeine.version>
+ <okhttp.version>3.9.0</okhttp.version>
</properties>
<dependencies>
@@ -154,6 +155,11 @@
<version>${gson.version}</version>
</dependency>
<dependency>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>okhttp</artifactId>
+ <version>${okhttp.version}</version>
+ </dependency>
+ <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
diff --git a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperConfig.java b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperConfig.java
index 769af78..7e679be 100644
--- a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperConfig.java
+++ b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperConfig.java
@@ -18,9 +18,9 @@
package org.apache.skywalking.oap.server.cluster.plugin.zookeeper;
+import com.google.common.base.Strings;
import lombok.*;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
/**
* @author peng-yongsheng
@@ -33,7 +33,7 @@
private int maxRetries;
public String getHostPort() {
- return StringUtils.isNotEmpty(hostPort) ? hostPort : "localhost:2181";
+ return Strings.isNullOrEmpty(hostPort) ? "localhost:2181" : hostPort;
}
public void setHostPort(String hostPort) {
diff --git a/oap-server/server-cluster-plugin/cluster_consul_plugin/pom.xml b/oap-server/server-cluster-plugin/cluster_consul_plugin/pom.xml
new file mode 100644
index 0000000..d9e6ed9
--- /dev/null
+++ b/oap-server/server-cluster-plugin/cluster_consul_plugin/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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
+ ~
+ ~ 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.
+ ~
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>server-cluster-plugin</artifactId>
+ <groupId>org.apache.skywalking</groupId>
+ <version>6.0.0-beta-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>cluster_consul_plugin</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
+ <artifactId>server-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.orbitz.consul</groupId>
+ <artifactId>consul-client</artifactId>
+ <version>1.2.6</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java b/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ClusterModuleConsulConfig.java
similarity index 63%
copy from oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java
copy to oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ClusterModuleConsulConfig.java
index 2d425c4..7203899 100644
--- a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java
+++ b/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ClusterModuleConsulConfig.java
@@ -16,24 +16,15 @@
*
*/
-package org.apache.skywalking.oap.server.library.util;
+package org.apache.skywalking.oap.server.cluster.plugin.consul;
+
+import lombok.*;
+import org.apache.skywalking.oap.server.library.module.ModuleConfig;
/**
* @author peng-yongsheng
*/
-public class StringUtils {
-
- public static final String EMPTY_STRING = "";
-
- public static boolean isEmpty(Object str) {
- return str == null || EMPTY_STRING.equals(str);
- }
-
- public static boolean isNotEmpty(Object str) {
- return !isEmpty(str);
- }
-
- public static String getOrDefault(String value, String defaultValue) {
- return value == null ? defaultValue : value;
- }
+class ClusterModuleConsulConfig extends ModuleConfig {
+ @Setter @Getter private String serviceName;
+ @Setter @Getter private String hostPort;
}
diff --git a/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ClusterModuleConsulProvider.java b/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ClusterModuleConsulProvider.java
new file mode 100644
index 0000000..cbafca7
--- /dev/null
+++ b/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ClusterModuleConsulProvider.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * 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.apache.skywalking.oap.server.cluster.plugin.consul;
+
+import com.google.common.net.HostAndPort;
+import com.orbitz.consul.Consul;
+import java.util.*;
+import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.cluster.*;
+import org.apache.skywalking.oap.server.library.module.*;
+import org.apache.skywalking.oap.server.library.util.*;
+import org.slf4j.*;
+
+/**
+ * Use consul to manage all service instances in SkyWalking cluster.
+ *
+ * @author peng-yongsheng
+ */
+public class ClusterModuleConsulProvider extends ModuleProvider {
+
+ private static final Logger logger = LoggerFactory.getLogger(ClusterModuleConsulProvider.class);
+
+ private final ClusterModuleConsulConfig config;
+ private Consul client;
+
+ public ClusterModuleConsulProvider() {
+ super();
+ this.config = new ClusterModuleConsulConfig();
+ }
+
+ @Override public String name() {
+ return "consul";
+ }
+
+ @Override public Class module() {
+ return ClusterModule.class;
+ }
+
+ @Override public ModuleConfig createConfigBeanIfAbsent() {
+ return config;
+ }
+
+ @Override public void prepare() throws ServiceNotProvidedException, ModuleStartException {
+ try {
+ List<Address> addressList = ConnectUtils.parse(config.getHostPort());
+
+ List<HostAndPort> hostAndPorts = new ArrayList<>();
+ for (Address address : addressList) {
+ hostAndPorts.add(HostAndPort.fromParts(address.getHost(), address.getPort()));
+ }
+
+ if (hostAndPorts.size() > 1) {
+ client = Consul.builder().withMultipleHostAndPort(hostAndPorts, 5000).build();
+ } else {
+ client = Consul.builder().withHostAndPort(hostAndPorts.get(0)).build();
+ }
+ } catch (ConnectStringParseException e) {
+ throw new ModuleStartException(e.getMessage(), e);
+ }
+
+ ConsulCoordinator coordinator = new ConsulCoordinator(client, config.getServiceName());
+ this.registerServiceImplementation(ClusterRegister.class, coordinator);
+ this.registerServiceImplementation(ClusterNodesQuery.class, coordinator);
+ }
+
+ @Override public void start() {
+ }
+
+ @Override public void notifyAfterCompleted() {
+ }
+
+ @Override
+ public String[] requiredModules() {
+ return new String[] {CoreModule.NAME};
+ }
+}
diff --git a/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ConsulCoordinator.java b/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ConsulCoordinator.java
new file mode 100644
index 0000000..bff8f24
--- /dev/null
+++ b/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/consul/ConsulCoordinator.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * 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.apache.skywalking.oap.server.cluster.plugin.consul;
+
+import com.google.common.base.Strings;
+import com.orbitz.consul.*;
+import com.orbitz.consul.model.agent.*;
+import com.orbitz.consul.model.health.ServiceHealth;
+import java.util.*;
+import org.apache.skywalking.oap.server.core.cluster.*;
+import org.apache.skywalking.oap.server.core.remote.client.Address;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class ConsulCoordinator implements ClusterRegister, ClusterNodesQuery {
+
+ private static final Logger logger = LoggerFactory.getLogger(ConsulCoordinator.class);
+
+ private final Consul client;
+ private final String serviceName;
+ private volatile Address selfAddress;
+
+ public ConsulCoordinator(Consul client, String serviceName) {
+ this.client = client;
+ this.serviceName = serviceName;
+ }
+
+ @Override public List<RemoteInstance> queryRemoteNodes() {
+ HealthClient healthClient = client.healthClient();
+
+ // Discover only "passing" nodes
+ List<ServiceHealth> nodes = healthClient.getHealthyServiceInstances(serviceName).getResponse();
+
+ List<RemoteInstance> remoteInstances = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(nodes)) {
+ nodes.forEach(node -> {
+ if (!Strings.isNullOrEmpty(node.getService().getAddress())) {
+ if (Objects.nonNull(selfAddress)) {
+ if (selfAddress.getHost().equals(node.getService().getAddress()) && selfAddress.getPort() == node.getService().getPort()) {
+ remoteInstances.add(new RemoteInstance(new Address(node.getService().getAddress(), node.getService().getPort(), true)));
+ } else {
+ remoteInstances.add(new RemoteInstance(new Address(node.getService().getAddress(), node.getService().getPort(), false)));
+ }
+ }
+ }
+ });
+ }
+ return remoteInstances;
+ }
+
+ @Override public void registerRemote(RemoteInstance remoteInstance) throws ServiceRegisterException {
+ AgentClient agentClient = client.agentClient();
+
+ this.selfAddress = remoteInstance.getAddress();
+
+ Registration registration = ImmutableRegistration.builder()
+ .id(remoteInstance.getAddress().toString())
+ .name(serviceName)
+ .address(remoteInstance.getAddress().getHost())
+ .port(remoteInstance.getAddress().getPort())
+ .check(Registration.RegCheck.grpc(remoteInstance.getAddress().getHost() + ":" + remoteInstance.getAddress().getPort(), 5)) // registers with a TTL of 5 seconds
+ .build();
+
+ agentClient.register(registration);
+ }
+}
diff --git a/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider b/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
new file mode 100644
index 0000000..14f1177
--- /dev/null
+++ b/oap-server/server-cluster-plugin/cluster_consul_plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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
+#
+# 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.
+#
+#
+
+org.apache.skywalking.oap.server.cluster.plugin.consul.ClusterModuleConsulProvider
\ No newline at end of file
diff --git a/oap-server/server-cluster-plugin/pom.xml b/oap-server/server-cluster-plugin/pom.xml
index d23af7a..d458868 100644
--- a/oap-server/server-cluster-plugin/pom.xml
+++ b/oap-server/server-cluster-plugin/pom.xml
@@ -31,6 +31,7 @@
<module>cluster-zookeeper-plugin</module>
<module>cluster-standalone-plugin</module>
<module>cluster-kubernetes-plugin</module>
+ <module>cluster_consul_plugin</module>
</modules>
<dependencies>
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java
index 457d814..93cfa80 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java
@@ -31,6 +31,7 @@
import org.apache.skywalking.oap.server.core.remote.*;
import org.apache.skywalking.oap.server.core.remote.annotation.*;
import org.apache.skywalking.oap.server.core.remote.client.*;
+import org.apache.skywalking.oap.server.core.remote.health.HealthCheckServiceHandler;
import org.apache.skywalking.oap.server.core.server.*;
import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.PersistenceTimer;
@@ -141,6 +142,7 @@
@Override public void start() throws ModuleStartException {
grpcServer.addHandler(new RemoteServiceHandler(getManager()));
+ grpcServer.addHandler(new HealthCheckServiceHandler());
remoteClientManager.start();
try {
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cache/NetworkAddressInventoryCache.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cache/NetworkAddressInventoryCache.java
index d9cd2fe..79ba73e 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cache/NetworkAddressInventoryCache.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cache/NetworkAddressInventoryCache.java
@@ -25,10 +25,9 @@
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.cache.INetworkAddressInventoryCacheDAO;
import org.apache.skywalking.oap.server.library.module.*;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.slf4j.*;
-import static java.util.Objects.isNull;
+import static java.util.Objects.*;
/**
* @author peng-yongsheng
@@ -72,7 +71,7 @@
if (isNull(networkAddress)) {
networkAddress = getCacheDAO().get(addressId);
- if (StringUtils.isNotEmpty(networkAddress)) {
+ if (nonNull(networkAddress)) {
addressIdCache.put(addressId, networkAddress);
}
}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java
index 33031ab..a571eeb 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java
@@ -27,9 +27,10 @@
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.query.*;
-import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.library.module.Service;
-import org.apache.skywalking.oap.server.library.util.*;
+import org.apache.skywalking.oap.server.library.module.*;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.elasticsearch.common.Strings;
import org.slf4j.*;
/**
@@ -126,7 +127,7 @@
if (CollectionUtils.isNotEmpty(sourceServiceIds)) {
List<Call> sourceCalls = getTopologyQueryDAO().loadSpecifiedServerSideServiceRelations(step, startTB, endTB, sourceServiceIds);
topology.getNodes().forEach(node -> {
- if (StringUtils.isEmpty(node.getType())) {
+ if (Strings.isNullOrEmpty(node.getType())) {
for (Call call : sourceCalls) {
if (node.getId() == call.getTarget()) {
node.setType(getComponentLibraryCatalogService().getComponentName(call.getComponentId()));
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/EndpointInventory.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/EndpointInventory.java
index ada737d..a643623 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/EndpointInventory.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/EndpointInventory.java
@@ -27,7 +27,7 @@
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
+import org.elasticsearch.common.Strings;
/**
* @author peng-yongsheng
@@ -91,7 +91,7 @@
remoteBuilder.addDataLongs(getRegisterTime());
remoteBuilder.addDataLongs(getHeartbeatTime());
- remoteBuilder.addDataStrings(StringUtils.getOrDefault(name, Const.EMPTY_STRING));
+ remoteBuilder.addDataStrings(Strings.isNullOrEmpty(name) ? Const.EMPTY_STRING : name);
return remoteBuilder;
}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/NetworkAddressInventory.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/NetworkAddressInventory.java
index 4ac144a..07d5bd8 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/NetworkAddressInventory.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/NetworkAddressInventory.java
@@ -27,7 +27,7 @@
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
+import org.elasticsearch.common.Strings;
/**
* @author peng-yongsheng
@@ -88,7 +88,7 @@
remoteBuilder.addDataLongs(getRegisterTime());
remoteBuilder.addDataLongs(getHeartbeatTime());
- remoteBuilder.addDataStrings(StringUtils.getOrDefault(name, Const.EMPTY_STRING));
+ remoteBuilder.addDataStrings(Strings.isNullOrEmpty(name) ? Const.EMPTY_STRING : name);
return remoteBuilder;
}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInstanceInventory.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInstanceInventory.java
index e94cec8..4e86974 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInstanceInventory.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInstanceInventory.java
@@ -30,7 +30,7 @@
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
+import org.elasticsearch.common.Strings;
/**
* @author peng-yongsheng
@@ -123,11 +123,11 @@
remoteBuilder.addDataLongs(getRegisterTime());
remoteBuilder.addDataLongs(getHeartbeatTime());
- remoteBuilder.addDataStrings(StringUtils.getOrDefault(name, Const.EMPTY_STRING));
- remoteBuilder.addDataStrings(StringUtils.getOrDefault(osName, Const.EMPTY_STRING));
- remoteBuilder.addDataStrings(StringUtils.getOrDefault(hostName, Const.EMPTY_STRING));
- remoteBuilder.addDataStrings(StringUtils.getOrDefault(ipv4s, Const.EMPTY_STRING));
- remoteBuilder.addDataStrings(StringUtils.getOrDefault(instanceUUID, Const.EMPTY_STRING));
+ remoteBuilder.addDataStrings(Strings.isNullOrEmpty(name) ? Const.EMPTY_STRING : name);
+ remoteBuilder.addDataStrings(Strings.isNullOrEmpty(osName) ? Const.EMPTY_STRING : osName);
+ remoteBuilder.addDataStrings(Strings.isNullOrEmpty(hostName) ? Const.EMPTY_STRING : hostName);
+ remoteBuilder.addDataStrings(Strings.isNullOrEmpty(ipv4s) ? Const.EMPTY_STRING : ipv4s);
+ remoteBuilder.addDataStrings(Strings.isNullOrEmpty(instanceUUID) ? Const.EMPTY_STRING : instanceUUID);
return remoteBuilder;
}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInventory.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInventory.java
index e97765a..386cef2 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInventory.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInventory.java
@@ -18,20 +18,17 @@
package org.apache.skywalking.oap.server.core.register;
-import java.util.HashMap;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
+import java.util.*;
+import lombok.*;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
-import org.apache.skywalking.oap.server.core.storage.annotation.Column;
-import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntity;
+import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
+import org.elasticsearch.common.Strings;
/**
* @author peng-yongsheng
@@ -123,7 +120,7 @@
remoteBuilder.addDataLongs(getHeartbeatTime());
remoteBuilder.addDataLongs(getMappingLastUpdateTime());
- remoteBuilder.addDataStrings(StringUtils.getOrDefault(name, Const.EMPTY_STRING));
+ remoteBuilder.addDataStrings(Strings.isNullOrEmpty(name) ? Const.EMPTY_STRING : name);
return remoteBuilder;
}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/remote/health/HealthCheckServiceHandler.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/remote/health/HealthCheckServiceHandler.java
new file mode 100644
index 0000000..cfcd724
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/remote/health/HealthCheckServiceHandler.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * 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.apache.skywalking.oap.server.core.remote.health;
+
+import grpc.health.v1.*;
+import io.grpc.stub.StreamObserver;
+import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class HealthCheckServiceHandler extends HealthGrpc.HealthImplBase implements GRPCHandler {
+
+ private static final Logger logger = LoggerFactory.getLogger(HealthCheckServiceHandler.class);
+
+ /**
+ * By my test, consul didn't send the service.
+ *
+ * @param request service
+ * @param responseObserver status
+ */
+ @Override public void check(HealthCheckService.HealthCheckRequest request,
+ StreamObserver<HealthCheckService.HealthCheckResponse> responseObserver) {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Received the gRPC server health check with the service name of {}", request.getService());
+ }
+
+ HealthCheckService.HealthCheckResponse.Builder response = HealthCheckService.HealthCheckResponse.newBuilder();
+ response.setStatus(HealthCheckService.HealthCheckResponse.ServingStatus.SERVING);
+
+ responseObserver.onNext(response.build());
+ responseObserver.onCompleted();
+ }
+}
diff --git a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java b/oap-server/server-core/src/main/proto/HealthCheckService.proto
similarity index 61%
copy from oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java
copy to oap-server/server-core/src/main/proto/HealthCheckService.proto
index 2d425c4..ecae37c 100644
--- a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java
+++ b/oap-server/server-core/src/main/proto/HealthCheckService.proto
@@ -16,24 +16,25 @@
*
*/
-package org.apache.skywalking.oap.server.library.util;
+//This is a health check proto, provided by gRPC team. Please don't change it.
+//https://github.com/grpc/grpc/blob/master/doc/health-checking.md
+syntax = "proto3";
-/**
- * @author peng-yongsheng
- */
-public class StringUtils {
+package grpc.health.v1;
- public static final String EMPTY_STRING = "";
-
- public static boolean isEmpty(Object str) {
- return str == null || EMPTY_STRING.equals(str);
- }
-
- public static boolean isNotEmpty(Object str) {
- return !isEmpty(str);
- }
-
- public static String getOrDefault(String value, String defaultValue) {
- return value == null ? defaultValue : value;
- }
+message HealthCheckRequest {
+ string service = 1;
}
+
+message HealthCheckResponse {
+ enum ServingStatus {
+ UNKNOWN = 0;
+ SERVING = 1;
+ NOT_SERVING = 2;
+ }
+ ServingStatus status = 1;
+}
+
+service Health {
+ rpc Check (HealthCheckRequest) returns (HealthCheckResponse);
+}
\ No newline at end of file
diff --git a/oap-server/server-library/library-server/src/main/java/org/apache/skywalking/oap/server/library/server/grpc/GRPCServer.java b/oap-server/server-library/library-server/src/main/java/org/apache/skywalking/oap/server/library/server/grpc/GRPCServer.java
index 8314829..86e67de 100644
--- a/oap-server/server-library/library-server/src/main/java/org/apache/skywalking/oap/server/library/server/grpc/GRPCServer.java
+++ b/oap-server/server-library/library-server/src/main/java/org/apache/skywalking/oap/server/library/server/grpc/GRPCServer.java
@@ -90,6 +90,7 @@
@Override
public void initialize() {
InetSocketAddress address = new InetSocketAddress(host, port);
+
nettyServerBuilder = NettyServerBuilder.forAddress(address);
nettyServerBuilder = nettyServerBuilder.maxConcurrentCallsPerConnection(maxConcurrentCallsPerConnection).maxMessageSize(maxMessageSize);
logger.info("Server started, host {} listening on {}", host, port);
diff --git a/oap-server/server-library/library-util/pom.xml b/oap-server/server-library/library-util/pom.xml
index 84577cd..38f20d0 100644
--- a/oap-server/server-library/library-util/pom.xml
+++ b/oap-server/server-library/library-util/pom.xml
@@ -37,7 +37,10 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
- <version>${joda-time.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
diff --git a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/Address.java
similarity index 68%
rename from oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java
rename to oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/Address.java
index 2d425c4..4e97e33 100644
--- a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java
+++ b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/Address.java
@@ -18,22 +18,14 @@
package org.apache.skywalking.oap.server.library.util;
+import lombok.*;
+
/**
* @author peng-yongsheng
*/
-public class StringUtils {
-
- public static final String EMPTY_STRING = "";
-
- public static boolean isEmpty(Object str) {
- return str == null || EMPTY_STRING.equals(str);
- }
-
- public static boolean isNotEmpty(Object str) {
- return !isEmpty(str);
- }
-
- public static String getOrDefault(String value, String defaultValue) {
- return value == null ? defaultValue : value;
- }
+@Getter
+@Setter
+public class Address {
+ private String host;
+ private int port;
}
diff --git a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ConnectStringParseException.java
similarity index 68%
copy from oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java
copy to oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ConnectStringParseException.java
index 2d425c4..959542a 100644
--- a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/StringUtils.java
+++ b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ConnectStringParseException.java
@@ -19,21 +19,13 @@
package org.apache.skywalking.oap.server.library.util;
/**
+ * Thrown if the given string which build with hosts and ports is incorrect.
+ *
* @author peng-yongsheng
*/
-public class StringUtils {
+public class ConnectStringParseException extends Exception {
- public static final String EMPTY_STRING = "";
-
- public static boolean isEmpty(Object str) {
- return str == null || EMPTY_STRING.equals(str);
- }
-
- public static boolean isNotEmpty(Object str) {
- return !isEmpty(str);
- }
-
- public static String getOrDefault(String value, String defaultValue) {
- return value == null ? defaultValue : value;
+ public ConnectStringParseException(String message) {
+ super(message);
}
}
diff --git a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ConnectUtils.java b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ConnectUtils.java
new file mode 100644
index 0000000..6f0939d
--- /dev/null
+++ b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ConnectUtils.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * 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.apache.skywalking.oap.server.library.util;
+
+import com.google.common.base.Strings;
+import java.util.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class ConnectUtils {
+
+ private ConnectUtils() {
+ }
+
+ public static List<Address> parse(String connectString) throws ConnectStringParseException {
+ connectString = connectString == null ? "" : connectString.trim();
+ connectString = connectString.startsWith(",") ? connectString.replace(",", "") : connectString;
+
+ if (Strings.isNullOrEmpty(connectString)) {
+ throw new ConnectStringParseException("ConnectString cannot be null or empty.");
+ }
+
+ List<Address> result = new ArrayList<>();
+
+ String[] connects = connectString.split(",");
+ for (String connect : connects) {
+ if (Strings.isNullOrEmpty(connect)) {
+ throw new ConnectStringParseException("Invalid connect string pattern.");
+ }
+
+ String[] hostAndPort = connect.split(":");
+ if (hostAndPort.length != 2) {
+ throw new ConnectStringParseException("Invalid connect string pattern.");
+ }
+
+ Address address = new Address();
+ address.setHost(hostAndPort[0]);
+
+ try {
+ address.setPort(Integer.parseInt(hostAndPort[1]));
+ } catch (NumberFormatException e) {
+ throw new ConnectStringParseException("Invalid connect string pattern.");
+ }
+ result.add(address);
+ }
+
+ return result;
+ }
+}
diff --git a/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/ConnectUtilTestCase.java b/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/ConnectUtilTestCase.java
new file mode 100644
index 0000000..55711fe
--- /dev/null
+++ b/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/ConnectUtilTestCase.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * 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.apache.skywalking.oap.server.library.util;
+
+import java.util.List;
+import org.junit.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class ConnectUtilTestCase {
+
+ @Test
+ public void parse() throws ConnectStringParseException {
+ List<Address> list = ConnectUtils.parse("10.0.0.1:1000,10.0.0.2:1001");
+ Assert.assertEquals(2, list.size());
+
+ Assert.assertEquals("10.0.0.1", list.get(0).getHost());
+ Assert.assertEquals(1000, list.get(0).getPort());
+
+ Assert.assertEquals("10.0.0.2", list.get(1).getHost());
+ Assert.assertEquals(1001, list.get(1).getPort());
+ }
+
+ @Test
+ public void comma() throws ConnectStringParseException {
+ List<Address> list = ConnectUtils.parse("10.0.0.1:1000,");
+
+ Assert.assertEquals(1, list.size());
+
+ Assert.assertEquals("10.0.0.1", list.get(0).getHost());
+ Assert.assertEquals(1000, list.get(0).getPort());
+
+ list = ConnectUtils.parse(",10.0.0.1:1000");
+
+ Assert.assertEquals(1, list.size());
+
+ Assert.assertEquals("10.0.0.1", list.get(0).getHost());
+ Assert.assertEquals(1000, list.get(0).getPort());
+ }
+
+ @Test(expected = ConnectStringParseException.class)
+ public void nullTest() throws ConnectStringParseException {
+ List<Address> list = ConnectUtils.parse(null);
+ }
+
+ @Test(expected = ConnectStringParseException.class)
+ public void emptyTest() throws ConnectStringParseException {
+ List<Address> list = ConnectUtils.parse("");
+ }
+
+ @Test(expected = ConnectStringParseException.class)
+ public void invalidPattern1() throws ConnectStringParseException {
+ List<Address> list = ConnectUtils.parse("10.0.0.1:");
+ }
+
+ @Test(expected = ConnectStringParseException.class)
+ public void invalidPattern2() throws ConnectStringParseException {
+ List<Address> list = ConnectUtils.parse("10.0.0.1:xx");
+ }
+}
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TraceQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TraceQuery.java
index 7bc4fe5..eb9f292 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TraceQuery.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/TraceQuery.java
@@ -19,13 +19,14 @@
package org.apache.skywalking.oap.query.graphql.resolver;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
+import com.google.common.base.Strings;
import java.io.IOException;
+import org.apache.commons.lang3.StringUtils;
import org.apache.skywalking.oap.query.graphql.type.TraceQueryCondition;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import static java.util.Objects.nonNull;
@@ -53,7 +54,7 @@
long endSecondTB = 0;
String traceId = Const.EMPTY_STRING;
- if (StringUtils.isNotEmpty(condition.getTraceId())) {
+ if (!Strings.isNullOrEmpty(condition.getTraceId())) {
traceId = condition.getTraceId();
} else if (nonNull(condition.getQueryDuration())) {
startSecondTB = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getStart());
diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/InstanceDiscoveryServiceHandler.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/InstanceDiscoveryServiceHandler.java
index b7893a8..f481e7d 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/InstanceDiscoveryServiceHandler.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/InstanceDiscoveryServiceHandler.java
@@ -18,18 +18,16 @@
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
+import com.google.common.base.Strings;
import io.grpc.stub.StreamObserver;
import java.util.Objects;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
-import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
-import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
-import org.apache.skywalking.oap.server.core.register.ServiceInventory;
+import org.apache.skywalking.oap.server.core.cache.*;
+import org.apache.skywalking.oap.server.core.register.*;
import org.apache.skywalking.oap.server.core.register.service.*;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.slf4j.*;
/**
@@ -67,7 +65,7 @@
if (osinfo.getProcessNo() != 0) {
instanceName += "-pid:" + osinfo.getProcessNo();
}
- if (StringUtils.isNotEmpty(osinfo.getHostname())) {
+ if (!Strings.isNullOrEmpty(osinfo.getHostname())) {
instanceName += "@" + osinfo.getHostname();
}
diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceDiscoveryServletHandler.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceDiscoveryServletHandler.java
index 81fc664..e000a33 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceDiscoveryServletHandler.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceDiscoveryServletHandler.java
@@ -18,17 +18,16 @@
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest;
+import com.google.common.base.Strings;
import com.google.gson.*;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
-import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
-import org.apache.skywalking.oap.server.core.register.ServiceInventory;
+import org.apache.skywalking.oap.server.core.register.*;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.jetty.*;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.slf4j.*;
/**
@@ -84,7 +83,7 @@
if (agentOsInfo.getProcessNo() != 0) {
instanceName += "-pid:" + agentOsInfo.getProcessNo();
}
- if (StringUtils.isNotEmpty(agentOsInfo.getHostname())) {
+ if (!Strings.isNullOrEmpty(agentOsInfo.getHostname())) {
instanceName += "@" + agentOsInfo.getHostname();
}
diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
index f08cc04..05c11d1 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
@@ -18,39 +18,20 @@
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v6.grpc;
+import com.google.common.base.Strings;
import io.grpc.stub.StreamObserver;
-import org.apache.skywalking.apm.network.common.Commands;
-import org.apache.skywalking.apm.network.common.KeyIntValuePair;
-import org.apache.skywalking.apm.network.common.KeyStringValuePair;
-import org.apache.skywalking.apm.network.register.v2.EndpointMapping;
-import org.apache.skywalking.apm.network.register.v2.EndpointMappingElement;
-import org.apache.skywalking.apm.network.register.v2.Enpoints;
-import org.apache.skywalking.apm.network.register.v2.NetAddressMapping;
-import org.apache.skywalking.apm.network.register.v2.NetAddresses;
-import org.apache.skywalking.apm.network.register.v2.RegisterGrpc;
-import org.apache.skywalking.apm.network.register.v2.ServiceAndNetworkAddressMappings;
-import org.apache.skywalking.apm.network.register.v2.ServiceInstanceRegisterMapping;
-import org.apache.skywalking.apm.network.register.v2.ServiceInstances;
-import org.apache.skywalking.apm.network.register.v2.ServiceRegisterMapping;
-import org.apache.skywalking.apm.network.register.v2.Services;
+import org.apache.skywalking.apm.network.common.*;
+import org.apache.skywalking.apm.network.register.v2.*;
import org.apache.skywalking.apm.util.StringUtil;
-import org.apache.skywalking.oap.server.core.Const;
-import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
-import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
-import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
-import org.apache.skywalking.oap.server.core.register.ServiceInventory;
-import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
-import org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
-import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
-import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
+import org.apache.skywalking.oap.server.core.*;
+import org.apache.skywalking.oap.server.core.cache.*;
+import org.apache.skywalking.oap.server.core.register.*;
+import org.apache.skywalking.oap.server.core.register.service.*;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc.InstanceDiscoveryServiceHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.slf4j.*;
/**
* @author wusheng
@@ -125,7 +106,7 @@
if (agentOsInfo.getProcessNo() != 0) {
instanceName += "-pid:" + agentOsInfo.getProcessNo();
}
- if (StringUtils.isNotEmpty(agentOsInfo.getHostname())) {
+ if (!Strings.isNullOrEmpty(agentOsInfo.getHostname())) {
instanceName += "@" + agentOsInfo.getHostname();
}
diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/ApplicationRegisterHandlerTestCase.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/ApplicationRegisterHandlerTestCase.java
index 19dbe67..474d07a 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/ApplicationRegisterHandlerTestCase.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/ApplicationRegisterHandlerTestCase.java
@@ -19,6 +19,7 @@
package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
import io.grpc.*;
+import io.grpc.stub.MetadataUtils;
import org.apache.skywalking.apm.network.language.agent.*;
import org.slf4j.*;
@@ -34,6 +35,10 @@
ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub stub = ApplicationRegisterServiceGrpc.newBlockingStub(channel);
+ Metadata authHeader = new Metadata();
+ authHeader.put(Metadata.Key.of("Authentication", Metadata.ASCII_STRING_MARSHALLER), "c4a4baabf931f2379bdfe53a450ecb89");
+ stub = MetadataUtils.attachHeaders(stub, authHeader);
+
Application.Builder application = Application.newBuilder();
application.setApplicationCode("dubbox-consumer");
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/ReferenceIdExchanger.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/ReferenceIdExchanger.java
index 8fc00a0..31d6368 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/ReferenceIdExchanger.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/ReferenceIdExchanger.java
@@ -18,12 +18,12 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization;
+import com.google.common.base.Strings;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.register.service.*;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.ReferenceDecorator;
import org.slf4j.*;
@@ -54,7 +54,7 @@
@Override public boolean exchange(ReferenceDecorator standardBuilder, int serviceId) {
if (standardBuilder.getEntryEndpointId() == 0) {
- String entryEndpointName = StringUtils.isNotEmpty(standardBuilder.getEntryEndpointName()) ? standardBuilder.getEntryEndpointName() : Const.DOMAIN_OPERATION_NAME;
+ String entryEndpointName = Strings.isNullOrEmpty(standardBuilder.getEntryEndpointName()) ? Const.DOMAIN_OPERATION_NAME : standardBuilder.getEntryEndpointName();
int entryEndpointId = endpointInventoryRegister.get(serviceInstanceInventoryCache.get(standardBuilder.getEntryServiceInstanceId()).getServiceId(), entryEndpointName, DetectPoint.SERVER.ordinal());
if (entryEndpointId == 0) {
@@ -71,7 +71,7 @@
}
if (standardBuilder.getParentEndpointId() == 0) {
- String parentEndpointName = StringUtils.isNotEmpty(standardBuilder.getParentEndpointName()) ? standardBuilder.getParentEndpointName() : Const.DOMAIN_OPERATION_NAME;
+ String parentEndpointName = Strings.isNullOrEmpty(standardBuilder.getParentEndpointName()) ? Const.DOMAIN_OPERATION_NAME : standardBuilder.getParentEndpointName();
int parentEndpointId = endpointInventoryRegister.get(serviceInstanceInventoryCache.get(standardBuilder.getParentServiceInstanceId()).getServiceId(), parentEndpointName, DetectPoint.SERVER.ordinal());
if (parentEndpointId == 0) {
@@ -87,7 +87,7 @@
}
}
- if (standardBuilder.getNetworkAddressId() == 0 && StringUtils.isNotEmpty(standardBuilder.getNetworkAddress())) {
+ if (standardBuilder.getNetworkAddressId() == 0 && !Strings.isNullOrEmpty(standardBuilder.getNetworkAddress())) {
int networkAddressId = networkAddressInventoryRegister.getOrCreate(standardBuilder.getNetworkAddress());
if (networkAddressId == 0) {
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanIdExchanger.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanIdExchanger.java
index 7e7f6a1..4d3aa46 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanIdExchanger.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanIdExchanger.java
@@ -18,12 +18,12 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization;
+import com.google.common.base.Strings;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.config.IComponentLibraryCatalogService;
import org.apache.skywalking.oap.server.core.register.service.*;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SpanDecorator;
import org.slf4j.*;
@@ -53,7 +53,7 @@
}
@Override public boolean exchange(SpanDecorator standardBuilder, int serviceId) {
- if (standardBuilder.getComponentId() == 0 && StringUtils.isNotEmpty(standardBuilder.getComponent())) {
+ if (standardBuilder.getComponentId() == 0 && !Strings.isNullOrEmpty(standardBuilder.getComponent())) {
int componentId = componentLibraryCatalogService.getComponentId(standardBuilder.getComponent());
if (componentId == 0) {
@@ -68,7 +68,7 @@
}
}
- if (standardBuilder.getPeerId() == 0 && StringUtils.isNotEmpty(standardBuilder.getPeer())) {
+ if (standardBuilder.getPeerId() == 0 && !Strings.isNullOrEmpty(standardBuilder.getPeer())) {
int peerId = networkAddressInventoryRegister.getOrCreate(standardBuilder.getPeer());
if (peerId == 0) {
@@ -87,7 +87,7 @@
}
if (standardBuilder.getOperationNameId() == 0) {
- String endpointName = StringUtils.isNotEmpty(standardBuilder.getOperationName()) ? standardBuilder.getOperationName() : Const.DOMAIN_OPERATION_NAME;
+ String endpointName = Strings.isNullOrEmpty(standardBuilder.getOperationName()) ? Const.DOMAIN_OPERATION_NAME : standardBuilder.getOperationName();
int endpointId = endpointInventoryRegister.getOrCreate(serviceId, endpointName, DetectPoint.fromSpanType(standardBuilder.getSpanType()));
if (endpointId == 0) {
diff --git a/oap-server/server-receiver-plugin/zipkin-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/zipkin/transform/SegmentBuilder.java b/oap-server/server-receiver-plugin/zipkin-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/zipkin/transform/SegmentBuilder.java
index a5ec97e..be1f1bb 100644
--- a/oap-server/server-receiver-plugin/zipkin-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/zipkin/transform/SegmentBuilder.java
+++ b/oap-server/server-receiver-plugin/zipkin-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/zipkin/transform/SegmentBuilder.java
@@ -18,30 +18,17 @@
package org.apache.skywalking.oap.server.receiver.zipkin.transform;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.TimeoutException;
+import com.google.common.base.Strings;
+import java.util.*;
+import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.logging.log4j.util.Strings;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
-import org.apache.skywalking.apm.network.language.agent.RefType;
-import org.apache.skywalking.apm.network.language.agent.SpanType;
-import org.apache.skywalking.apm.network.language.agent.UniqueId;
-import org.apache.skywalking.apm.network.language.agent.v2.Log;
-import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
-import org.apache.skywalking.apm.network.language.agent.v2.SegmentReference;
-import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
-import org.apache.skywalking.oap.server.receiver.zipkin.CoreRegisterLinker;
-import org.apache.skywalking.oap.server.receiver.zipkin.ZipkinTraceOSInfoBuilder;
+import org.apache.skywalking.apm.network.language.agent.*;
+import org.apache.skywalking.apm.network.language.agent.v2.*;
+import org.apache.skywalking.oap.server.receiver.zipkin.*;
import org.apache.skywalking.oap.server.receiver.zipkin.data.SkyWalkingTrace;
import org.eclipse.jetty.util.StringUtil;
-import zipkin2.Endpoint;
-import zipkin2.Span;
+import zipkin2.*;
/**
* @author wusheng
@@ -87,7 +74,7 @@
// Ignore the whole trace.
// :P Hope anyone could provide better solution.
// Wu Sheng.
- if (StringUtils.isNotEmpty(applicationCode)) {
+ if (!Strings.isNullOrEmpty(applicationCode)) {
timestamp = rootSpan.timestampAsLong();
builder.context.addApp(applicationCode, rootSpan.timestampAsLong() / 1000);
@@ -158,7 +145,7 @@
spanBuilder.setParentSpanId(parentSegmentSpan.getSpanId());
}
Span.Kind kind = span.kind();
- String opName = Strings.isBlank(span.name()) ? "-" : span.name();
+ String opName = Strings.isNullOrEmpty(span.name()) ? "-" : span.name();
spanBuilder.setOperationName(opName);
ClientSideSpan clientSideSpan;
switch (kind) {
@@ -287,10 +274,10 @@
Integer port = 0;
if (endpoint != null) {
- if (StringUtils.isNotEmpty(endpoint.ipv4())) {
+ if (!Strings.isNullOrEmpty(endpoint.ipv4())) {
ip = endpoint.ipv4();
port = endpoint.port();
- } else if (StringUtils.isNotEmpty(endpoint.ipv6())) {
+ } else if (!Strings.isNullOrEmpty(endpoint.ipv6())) {
ip = endpoint.ipv6();
port = endpoint.port();
}
@@ -309,7 +296,7 @@
private LinkedList<Segment> segmentsStack = new LinkedList<>();
private boolean isAppChanged(String applicationCode) {
- return StringUtils.isNotEmpty(applicationCode) && !applicationCode.equals(currentIDs().applicationCode);
+ return !Strings.isNullOrEmpty(applicationCode) && !applicationCode.equals(currentIDs().applicationCode);
}
private Segment addApp(String serviceCode, long registerTime) throws Exception {
@@ -394,9 +381,9 @@
private void addSpan(SpanObjectV2.Builder spanBuilder) {
String operationName = spanBuilder.getOperationName();
- if (entryEndpointId == 0 && StringUtils.isNotEmpty(operationName)) {
+ if (entryEndpointId == 0 && !Strings.isNullOrEmpty(operationName)) {
if (SpanType.Entry == spanBuilder.getSpanType()) {
- if (StringUtils.isNotEmpty(operationName)) {
+ if (!Strings.isNullOrEmpty(operationName)) {
entryEndpointName = operationName;
} else {
entryEndpointId = spanBuilder.getOperationNameId();
@@ -406,7 +393,7 @@
// init by root span
if (spanBuilder.getSpanId() == 1 && entryEndpointId == 0) {
- if (StringUtils.isNotEmpty(operationName)) {
+ if (!Strings.isNullOrEmpty(operationName)) {
entryEndpointName = operationName;
} else {
entryEndpointId = spanBuilder.getOperationNameId();
diff --git a/oap-server/server-starter/pom.xml b/oap-server/server-starter/pom.xml
index 28bc10a..c522862 100644
--- a/oap-server/server-starter/pom.xml
+++ b/oap-server/server-starter/pom.xml
@@ -66,6 +66,11 @@
<artifactId>cluster-kubernetes-plugin</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
+ <artifactId>cluster_consul_plugin</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- cluster module -->
<!-- receiver module -->
diff --git a/oap-server/server-starter/src/main/assembly/application.yml b/oap-server/server-starter/src/main/assembly/application.yml
index 362aca1..7324012 100644
--- a/oap-server/server-starter/src/main/assembly/application.yml
+++ b/oap-server/server-starter/src/main/assembly/application.yml
@@ -19,6 +19,7 @@
# Please check your ZooKeeper is 3.5+, However, it is also compatible with ZooKeeper 3.4.x. Replace the ZooKeeper 3.5+
# library the oap-libs folder with your ZooKeeper 3.4.x library.
# zookeeper:
+# nameSpace: ${SW_NAMESPACE:""}
# hostPort: ${SW_CLUSTER_ZK_HOST_PORT:localhost:2181}
# #Retry Policy
# baseSleepTimeMs: ${SW_CLUSTER_ZK_SLEEP_TIME:1000} # initial amount of time to wait between retries
@@ -28,6 +29,10 @@
# namespace: ${SW_CLUSTER_K8S_NAMESPACE:default}
# labelSelector: ${SW_CLUSTER_K8S_LABEL:app=collector,release=skywalking}
# uidEnvName: ${SW_CLUSTER_K8S_UID:SKYWALKING_COLLECTOR_UID}
+# consul:
+# serviceName: ${SW_SERVICE_NAME:"SkyWalking_OAP_Cluster"}
+# Consul cluster nodes, example: 10.0.0.1:8500,10.0.0.2:8500,10.0.0.3:8500
+# hostPort: ${SW_CLUSTER_CONSUL_HOST_PORT:localhost:8500}
core:
default:
restHost: ${SW_CORE_REST_HOST:0.0.0.0}
@@ -72,14 +77,14 @@
sampleRate: ${SW_TRACE_SAMPLE_RATE:10000} # The sample rate precision is 1/10000. 10000 means 100% sample in default.
receiver-jvm:
default:
-service-mesh:
- default:
- bufferPath: ${SW_SERVICE_MESH_BUFFER_PATH:../mesh-buffer/} # Path to trace buffer files, suggest to use absolute path
- bufferOffsetMaxFileSize: ${SW_SERVICE_MESH_OFFSET_MAX_FILE_SIZE:100} # Unit is MB
- bufferDataMaxFileSize: ${SW_SERVICE_MESH_BUFFER_DATA_MAX_FILE_SIZE:500} # Unit is MB
- bufferFileCleanWhenRestart: ${SW_SERVICE_MESH_BUFFER_FILE_CLEAN_WHEN_RESTART:false}
-istio-telemetry:
- default:
+#service-mesh:
+# default:
+# bufferPath: ${SW_SERVICE_MESH_BUFFER_PATH:../mesh-buffer/} # Path to trace buffer files, suggest to use absolute path
+# bufferOffsetMaxFileSize: ${SW_SERVICE_MESH_OFFSET_MAX_FILE_SIZE:100} # Unit is MB
+# bufferDataMaxFileSize: ${SW_SERVICE_MESH_BUFFER_DATA_MAX_FILE_SIZE:500} # Unit is MB
+# bufferFileCleanWhenRestart: ${SW_SERVICE_MESH_BUFFER_FILE_CLEAN_WHEN_RESTART:false}
+#istio-telemetry:
+# default:
#receiver_zipkin:
# default:
# host: ${SW_RECEIVER_ZIPKIN_HOST:0.0.0.0}
diff --git a/oap-server/server-starter/src/main/resources/application.yml b/oap-server/server-starter/src/main/resources/application.yml
index d2e7a4a..4312eba 100644
--- a/oap-server/server-starter/src/main/resources/application.yml
+++ b/oap-server/server-starter/src/main/resources/application.yml
@@ -29,6 +29,10 @@
# namespace: ${SW_CLUSTER_K8S_NAMESPACE:default}
# labelSelector: ${SW_CLUSTER_K8S_LABEL:app=collector,release=skywalking}
# uidEnvName: ${SW_CLUSTER_K8S_UID:SKYWALKING_COLLECTOR_UID}
+# consul:
+# serviceName: ${SW_SERVICE_NAME:"SkyWalking_OAP_Cluster"}
+# Consul cluster nodes, example: 10.0.0.1:8500,10.0.0.2:8500,10.0.0.3:8500
+# hostPort: ${SW_CLUSTER_CONSUL_HOST_PORT:localhost:8500}
core:
default:
restHost: ${SW_CORE_REST_HOST:0.0.0.0}
@@ -37,9 +41,9 @@
gRPCHost: ${SW_CORE_GRPC_HOST:0.0.0.0}
gRPCPort: ${SW_CORE_GRPC_PORT:11800}
downsampling:
- - Hour
- - Day
- - Month
+ - Hour
+ - Day
+ - Month
# Set a timeout on metric data. After the timeout has expired, the metric data will automatically be deleted.
recordDataTTL: ${SW_CORE_RECORD_DATA_TTL:90} # Unit is minute
minuteMetricsDataTTL: ${SW_CORE_MINUTE_METRIC_DATA_TTL:90} # Unit is minute
@@ -49,7 +53,7 @@
storage:
elasticsearch:
nameSpace: ${SW_NAMESPACE:""}
- clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:10.67.27.213:9200}
+ clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
# Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
@@ -81,11 +85,11 @@
bufferFileCleanWhenRestart: ${SW_SERVICE_MESH_BUFFER_FILE_CLEAN_WHEN_RESTART:false}
istio-telemetry:
default:
-receiver_zipkin:
- default:
- host: ${SW_RECEIVER_ZIPKIN_HOST:0.0.0.0}
- port: ${SW_RECEIVER_ZIPKIN_PORT:9411}
- contextPath: ${SW_RECEIVER_ZIPKIN_CONTEXT_PATH:/}
+#receiver_zipkin:
+# default:
+# host: ${SW_RECEIVER_ZIPKIN_HOST:0.0.0.0}
+# port: ${SW_RECEIVER_ZIPKIN_PORT:9411}
+# contextPath: ${SW_RECEIVER_ZIPKIN_CONTEXT_PATH:/}
query:
graphql:
path: ${SW_QUERY_GRAPHQL_PATH:/graphql}
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AlarmQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AlarmQueryEsDAO.java
index 942c3d7..24272ec 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AlarmQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AlarmQueryEsDAO.java
@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
+import com.google.common.base.Strings;
import java.io.IOException;
import java.util.Objects;
import org.apache.skywalking.oap.server.core.alarm.AlarmRecord;
@@ -25,7 +26,6 @@
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.*;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.*;
@@ -52,7 +52,7 @@
boolQueryBuilder.must().add(QueryBuilders.termQuery(AlarmRecord.SCOPE, scope.ordinal()));
}
- if (StringUtils.isNotEmpty(keyword)) {
+ if (!Strings.isNullOrEmpty(keyword)) {
String matchCName = MatchCNameBuilder.INSTANCE.build(AlarmRecord.ALARM_MESSAGE);
boolQueryBuilder.must().add(QueryBuilders.matchQuery(matchCName, keyword));
}
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetadataQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetadataQueryEsDAO.java
index 4af64ce..f4a296c 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetadataQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetadataQueryEsDAO.java
@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
+import com.google.common.base.Strings;
import java.io.IOException;
import java.util.*;
import org.apache.skywalking.oap.server.core.query.entity.*;
@@ -25,7 +26,7 @@
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.storage.query.IMetadataQueryDAO;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
-import org.apache.skywalking.oap.server.library.util.*;
+import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.*;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse;
@@ -107,7 +108,7 @@
boolQueryBuilder.must().add(timeRangeQueryBuild(startTimestamp, endTimestamp));
boolQueryBuilder.must().add(QueryBuilders.termQuery(ServiceInventory.IS_ADDRESS, BooleanUtils.FALSE));
- if (StringUtils.isNotEmpty(keyword)) {
+ if (!Strings.isNullOrEmpty(keyword)) {
String matchCName = MatchCNameBuilder.INSTANCE.build(ServiceInventory.NAME);
boolQueryBuilder.must().add(QueryBuilders.matchQuery(matchCName, keyword));
}
@@ -139,7 +140,7 @@
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must().add(QueryBuilders.termQuery(EndpointInventory.SERVICE_ID, serviceId));
- if (StringUtils.isNotEmpty(keyword)) {
+ if (!Strings.isNullOrEmpty(keyword)) {
String matchCName = MatchCNameBuilder.INSTANCE.build(EndpointInventory.NAME);
boolQueryBuilder.must().add(QueryBuilders.matchQuery(matchCName, keyword));
}
@@ -189,11 +190,11 @@
serviceInstance.setLanguage(LanguageTrans.INSTANCE.value(languageId));
String osName = (String)sourceAsMap.get(ServiceInstanceInventory.OS_NAME);
- if (StringUtils.isNotEmpty(osName)) {
+ if (!Strings.isNullOrEmpty(osName)) {
serviceInstance.getAttributes().add(new Attribute(ServiceInstanceInventory.OS_NAME, osName));
}
String hostName = (String)sourceAsMap.get(ServiceInstanceInventory.HOST_NAME);
- if (StringUtils.isNotEmpty(hostName)) {
+ if (!Strings.isNullOrEmpty(hostName)) {
serviceInstance.getAttributes().add(new Attribute(ServiceInstanceInventory.HOST_NAME, hostName));
}
serviceInstance.getAttributes().add(new Attribute(ServiceInstanceInventory.PROCESS_NO, String.valueOf(((Number)sourceAsMap.get(ServiceInstanceInventory.PROCESS_NO)).intValue())));
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TraceQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TraceQueryEsDAO.java
index e1e091e..bffed1f 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TraceQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TraceQueryEsDAO.java
@@ -18,25 +18,17 @@
package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
+import com.google.common.base.Strings;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.List;
+import java.util.*;
import org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
-import org.apache.skywalking.oap.server.core.query.entity.BasicTrace;
-import org.apache.skywalking.oap.server.core.query.entity.QueryOrder;
-import org.apache.skywalking.oap.server.core.query.entity.TraceBrief;
-import org.apache.skywalking.oap.server.core.query.entity.TraceState;
+import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.storage.query.ITraceQueryDAO;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO;
import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.index.query.RangeQueryBuilder;
+import org.elasticsearch.index.query.*;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
@@ -74,7 +66,7 @@
}
boolQueryBuilder.must().add(rangeQueryBuilder);
}
- if (StringUtils.isNotEmpty(endpointName)) {
+ if (!Strings.isNullOrEmpty(endpointName)) {
mustQueryList.add(QueryBuilders.matchPhraseQuery(SegmentRecord.ENDPOINT_NAME, endpointName));
}
if (serviceId != 0) {
@@ -83,7 +75,7 @@
if (endpointId != 0) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentRecord.ENDPOINT_ID, endpointId));
}
- if (StringUtils.isNotEmpty(traceId)) {
+ if (!Strings.isNullOrEmpty(traceId)) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentRecord.TRACE_ID, traceId));
}
switch (traceState) {
@@ -144,7 +136,7 @@
segmentRecord.setLatency(((Number)searchHit.getSourceAsMap().get(SegmentRecord.LATENCY)).intValue());
segmentRecord.setIsError(((Number)searchHit.getSourceAsMap().get(SegmentRecord.IS_ERROR)).intValue());
String dataBinaryBase64 = (String)searchHit.getSourceAsMap().get(SegmentRecord.DATA_BINARY);
- if (StringUtils.isNotEmpty(dataBinaryBase64)) {
+ if (!Strings.isNullOrEmpty(dataBinaryBase64)) {
segmentRecord.setDataBinary(Base64.getDecoder().decode(dataBinaryBase64));
}
segmentRecord.setVersion(((Number)searchHit.getSourceAsMap().get(SegmentRecord.VERSION)).intValue());
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2AlarmQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2AlarmQueryDAO.java
index daa2b24..1fa18f9 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2AlarmQueryDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2AlarmQueryDAO.java
@@ -19,18 +19,14 @@
package org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
+import java.sql.*;
+import java.util.*;
import org.apache.skywalking.oap.server.core.alarm.AlarmRecord;
-import org.apache.skywalking.oap.server.core.query.entity.AlarmMessage;
-import org.apache.skywalking.oap.server.core.query.entity.Alarms;
+import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
+import org.elasticsearch.common.Strings;
/**
* @author wusheng
@@ -57,7 +53,7 @@
parameters.add(endTB);
}
- if (StringUtils.isNotEmpty(keyword)) {
+ if (!Strings.isNullOrEmpty(keyword)) {
sql.append(" and ").append(AlarmRecord.ALARM_MESSAGE).append(" like '%").append(keyword).append("%' ");
}
sql.append(" order by ").append(AlarmRecord.START_TIME).append(" desc ");
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetadataQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetadataQueryDAO.java
index b6c6681..5576609 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetadataQueryDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetadataQueryDAO.java
@@ -18,27 +18,16 @@
package org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao;
+import com.google.common.base.Strings;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.skywalking.oap.server.core.query.entity.Attribute;
-import org.apache.skywalking.oap.server.core.query.entity.Endpoint;
-import org.apache.skywalking.oap.server.core.query.entity.LanguageTrans;
-import org.apache.skywalking.oap.server.core.query.entity.Service;
-import org.apache.skywalking.oap.server.core.query.entity.ServiceInstance;
-import org.apache.skywalking.oap.server.core.register.EndpointInventory;
-import org.apache.skywalking.oap.server.core.register.NetworkAddressInventory;
-import org.apache.skywalking.oap.server.core.register.RegisterSource;
-import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
-import org.apache.skywalking.oap.server.core.register.ServiceInventory;
+import java.sql.*;
+import java.util.*;
+import org.apache.skywalking.oap.server.core.query.entity.*;
+import org.apache.skywalking.oap.server.core.register.*;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.storage.query.IMetadataQueryDAO;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
/**
* @author wusheng
@@ -134,7 +123,7 @@
setTimeRangeCondition(sql, condition, startTimestamp, endTimestamp);
sql.append(" and ").append(ServiceInventory.IS_ADDRESS).append("=?");
condition.add(BooleanUtils.FALSE);
- if (StringUtils.isNotEmpty(keyword)) {
+ if (!Strings.isNullOrEmpty(keyword)) {
sql.append(" and ").append(ServiceInventory.NAME).append(" like \"%").append(keyword).append("%\"");
}
sql.append(" limit 100");
@@ -181,7 +170,7 @@
sql.append("select * from ").append(EndpointInventory.MODEL_NAME).append(" where ");
sql.append(EndpointInventory.SERVICE_ID).append("=?");
condition.add(serviceId);
- if (StringUtils.isNotEmpty(keyword)) {
+ if (!Strings.isNullOrEmpty(keyword)) {
sql.append(" and ").append(EndpointInventory.NAME).append(" like \"%").append(keyword).append("%\" ");
}
sql.append(" and ").append(EndpointInventory.DETECT_POINT).append(" = ?");
@@ -226,11 +215,11 @@
serviceInstance.setLanguage(LanguageTrans.INSTANCE.value(languageId));
String osName = resultSet.getString(ServiceInstanceInventory.OS_NAME);
- if (StringUtils.isNotEmpty(osName)) {
+ if (!Strings.isNullOrEmpty(osName)) {
serviceInstance.getAttributes().add(new Attribute(ServiceInstanceInventory.OS_NAME, osName));
}
String hostName = resultSet.getString(ServiceInstanceInventory.HOST_NAME);
- if (StringUtils.isNotEmpty(hostName)) {
+ if (!Strings.isNullOrEmpty(hostName)) {
serviceInstance.getAttributes().add(new Attribute(ServiceInstanceInventory.HOST_NAME, hostName));
}
serviceInstance.getAttributes().add(new Attribute(ServiceInstanceInventory.PROCESS_NO, resultSet.getString(ServiceInstanceInventory.PROCESS_NO)));
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TraceQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TraceQueryDAO.java
index 08e352e..277bd97 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TraceQueryDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TraceQueryDAO.java
@@ -18,22 +18,15 @@
package org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao;
+import com.google.common.base.Strings;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.List;
+import java.sql.*;
+import java.util.*;
import org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
-import org.apache.skywalking.oap.server.core.query.entity.BasicTrace;
-import org.apache.skywalking.oap.server.core.query.entity.QueryOrder;
-import org.apache.skywalking.oap.server.core.query.entity.TraceBrief;
-import org.apache.skywalking.oap.server.core.query.entity.TraceState;
+import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.storage.query.ITraceQueryDAO;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.elasticsearch.search.sort.SortOrder;
/**
@@ -71,7 +64,7 @@
parameters.add(maxDuration);
}
}
- if (StringUtils.isNotEmpty(endpointName)) {
+ if (!Strings.isNullOrEmpty(endpointName)) {
sql.append(" and ").append(SegmentRecord.ENDPOINT_NAME).append(" like '%" + endpointName + "%'");
}
if (serviceId != 0) {
@@ -82,7 +75,7 @@
sql.append(" and ").append(SegmentRecord.ENDPOINT_ID).append(" = ?");
parameters.add(endpointId);
}
- if (StringUtils.isNotEmpty(traceId)) {
+ if (!Strings.isNullOrEmpty(traceId)) {
sql.append(" and ").append(SegmentRecord.TRACE_ID).append(" = ?");
parameters.add(traceId);
}
@@ -156,7 +149,7 @@
segmentRecord.setLatency(resultSet.getInt(SegmentRecord.LATENCY));
segmentRecord.setIsError(resultSet.getInt(SegmentRecord.IS_ERROR));
String dataBinaryBase64 = resultSet.getString(SegmentRecord.DATA_BINARY);
- if (StringUtils.isNotEmpty(dataBinaryBase64)) {
+ if (!Strings.isNullOrEmpty(dataBinaryBase64)) {
segmentRecord.setDataBinary(Base64.getDecoder().decode(dataBinaryBase64));
}
segmentRecord.setVersion(resultSet.getInt(SegmentRecord.VERSION));
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLAlarmQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLAlarmQueryDAO.java
index 38ce85c..582a01e 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLAlarmQueryDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLAlarmQueryDAO.java
@@ -19,18 +19,14 @@
package org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
+import java.sql.*;
+import java.util.*;
import org.apache.skywalking.oap.server.core.alarm.AlarmRecord;
-import org.apache.skywalking.oap.server.core.query.entity.AlarmMessage;
-import org.apache.skywalking.oap.server.core.query.entity.Alarms;
+import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
+import org.elasticsearch.common.Strings;
/**
* @author wusheng
@@ -58,7 +54,7 @@
parameters.add(endTB);
}
- if (StringUtils.isNotEmpty(keyword)) {
+ if (!Strings.isNullOrEmpty(keyword)) {
sql.append(" and ").append(AlarmRecord.ALARM_MESSAGE).append(" like '%").append(keyword).append("%' ");
}
sql.append(" order by ").append(AlarmRecord.START_TIME).append(" desc ");
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLTraceQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLTraceQueryDAO.java
index 8a94176..ddd36a5 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLTraceQueryDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLTraceQueryDAO.java
@@ -18,27 +18,21 @@
package org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql;
+import com.google.common.base.Strings;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
+import java.sql.*;
+import java.util.*;
import org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
-import org.apache.skywalking.oap.server.core.query.entity.BasicTrace;
-import org.apache.skywalking.oap.server.core.query.entity.QueryOrder;
-import org.apache.skywalking.oap.server.core.query.entity.TraceBrief;
-import org.apache.skywalking.oap.server.core.query.entity.TraceState;
+import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
-import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2TraceQueryDAO;
import org.elasticsearch.search.sort.SortOrder;
/**
* @author wusheng
*/
-public class MySQLTraceQueryDAO extends H2TraceQueryDAO {
+public class MySQLTraceQueryDAO extends H2TraceQueryDAO {
public MySQLTraceQueryDAO(JDBCHikariCPClient mysqlClient) {
super(mysqlClient);
}
@@ -68,7 +62,7 @@
parameters.add(maxDuration);
}
}
- if (StringUtils.isNotEmpty(endpointName)) {
+ if (!Strings.isNullOrEmpty(endpointName)) {
sql.append(" and ").append(SegmentRecord.ENDPOINT_NAME).append(" like '%" + endpointName + "%'");
}
if (serviceId != 0) {
@@ -79,7 +73,7 @@
sql.append(" and ").append(SegmentRecord.ENDPOINT_ID).append(" = ?");
parameters.add(endpointId);
}
- if (StringUtils.isNotEmpty(traceId)) {
+ if (!Strings.isNullOrEmpty(traceId)) {
sql.append(" and ").append(SegmentRecord.TRACE_ID).append(" = ?");
parameters.add(traceId);
}