|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.skywalking.oap.query.debug; |
| 20 | + |
| 21 | +import com.google.gson.JsonArray; |
| 22 | +import com.google.gson.JsonObject; |
| 23 | +import com.linecorp.armeria.common.HttpRequest; |
| 24 | +import com.linecorp.armeria.common.HttpResponse; |
| 25 | +import com.linecorp.armeria.common.MediaType; |
| 26 | +import com.linecorp.armeria.server.annotation.ExceptionHandler; |
| 27 | +import com.linecorp.armeria.server.annotation.Get; |
| 28 | +import lombok.extern.slf4j.Slf4j; |
| 29 | +import org.apache.skywalking.oap.server.core.CoreModule; |
| 30 | +import org.apache.skywalking.oap.server.core.remote.client.Address; |
| 31 | +import org.apache.skywalking.oap.server.core.remote.client.RemoteClientManager; |
| 32 | +import org.apache.skywalking.oap.server.library.module.ModuleManager; |
| 33 | + |
| 34 | +@Slf4j |
| 35 | +@ExceptionHandler(StatusQueryExceptionHandler.class) |
| 36 | +public class ClusterStatusQueryHandler { |
| 37 | + private final ModuleManager moduleManager; |
| 38 | + private RemoteClientManager remoteClientManager; |
| 39 | + |
| 40 | + public ClusterStatusQueryHandler(final ModuleManager manager) { |
| 41 | + this.moduleManager = manager; |
| 42 | + } |
| 43 | + |
| 44 | + private RemoteClientManager getRemoteClientManager() { |
| 45 | + if (remoteClientManager == null) { |
| 46 | + remoteClientManager = moduleManager.find(CoreModule.NAME) |
| 47 | + .provider() |
| 48 | + .getService(RemoteClientManager.class); |
| 49 | + } |
| 50 | + return remoteClientManager; |
| 51 | + } |
| 52 | + |
| 53 | + @Get("/status/cluster/nodes") |
| 54 | + public HttpResponse buildClusterNodeList(HttpRequest request) { |
| 55 | + JsonObject clusterInfo = new JsonObject(); |
| 56 | + |
| 57 | + JsonArray nodeList = new JsonArray(); |
| 58 | + clusterInfo.add("nodes", nodeList); |
| 59 | + getRemoteClientManager().getRemoteClient().stream().map(c -> { |
| 60 | + final Address address = c.getAddress(); |
| 61 | + JsonObject node = new JsonObject(); |
| 62 | + node.addProperty("host", address.getHost()); |
| 63 | + node.addProperty("port", address.getPort()); |
| 64 | + node.addProperty("isSelf", address.isSelf()); |
| 65 | + return node; |
| 66 | + }).forEach(nodeList::add); |
| 67 | + |
| 68 | + return HttpResponse.of(MediaType.JSON_UTF_8, clusterInfo.toString()); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments