diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetadataQueryService.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetadataQueryService.java index c7ef7207f919ce3744e99a75eaba02a0561e2933..252ce72bc9b8440167e29a4a3fcf9e9a4b452f07 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetadataQueryService.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetadataQueryService.java @@ -21,7 +21,10 @@ package org.apache.skywalking.oap.server.core.query; import java.io.IOException; import java.util.List; import org.apache.skywalking.apm.network.language.agent.SpanLayer; +import org.apache.skywalking.oap.server.core.CoreModule; +import org.apache.skywalking.oap.server.core.cache.*; import org.apache.skywalking.oap.server.core.query.entity.*; +import org.apache.skywalking.oap.server.core.register.EndpointInventory; import org.apache.skywalking.oap.server.core.storage.StorageModule; import org.apache.skywalking.oap.server.core.storage.query.IMetadataQueryDAO; import org.apache.skywalking.oap.server.library.module.ModuleManager; @@ -33,18 +36,34 @@ public class MetadataQueryService implements org.apache.skywalking.oap.server.li private final ModuleManager moduleManager; private IMetadataQueryDAO metadataQueryDAO; + private ServiceInventoryCache serviceInventoryCache; + private EndpointInventoryCache endpointInventoryCache; public MetadataQueryService(ModuleManager moduleManager) { this.moduleManager = moduleManager; } - public IMetadataQueryDAO getMetadataQueryDAO() { + private IMetadataQueryDAO getMetadataQueryDAO() { if (metadataQueryDAO == null) { metadataQueryDAO = moduleManager.find(StorageModule.NAME).getService(IMetadataQueryDAO.class); } return metadataQueryDAO; } + private ServiceInventoryCache getServiceInventoryCache() { + if (serviceInventoryCache == null) { + serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class); + } + return serviceInventoryCache; + } + + private EndpointInventoryCache getEndpointInventoryCache() { + if (endpointInventoryCache == null) { + endpointInventoryCache = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class); + } + return endpointInventoryCache; + } + public ClusterBrief getGlobalBrief(final long startTimestamp, final long endTimestamp) throws IOException { ClusterBrief clusterBrief = new ClusterBrief(); clusterBrief.setNumOfService(getMetadataQueryDAO().numOfService(startTimestamp, endTimestamp)); @@ -77,4 +96,15 @@ public class MetadataQueryService implements org.apache.skywalking.oap.server.li public Service searchService(final String serviceCode) throws IOException { return getMetadataQueryDAO().searchService(serviceCode); } + + public EndpointInfo getEndpointInfo(final int endpointId) throws IOException { + EndpointInventory endpointInventory = getEndpointInventoryCache().get(endpointId); + + EndpointInfo endpointInfo = new EndpointInfo(); + endpointInfo.setId(endpointInventory.getSequence()); + endpointInfo.setName(endpointInventory.getName()); + endpointInfo.setServiceId(endpointInventory.getServiceId()); + endpointInfo.setServiceName(getServiceInventoryCache().get(endpointInventory.getServiceId()).getName()); + return endpointInfo; + } } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Endpoint.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Endpoint.java index cf98063c2159a30bd4c011a50ed13416fe5b5f7d..f325d6c4e93505cf369ac4e725ebd92506b18841 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Endpoint.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Endpoint.java @@ -26,6 +26,6 @@ import lombok.*; @Getter @Setter public class Endpoint { - private String id; + private int id; private String name; } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/EndpointInfo.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/EndpointInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..f18d5bae2cd23413eedc4234490695c97bdf20d9 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/EndpointInfo.java @@ -0,0 +1,33 @@ +/* + * 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.query.entity; + +import lombok.*; + +/** + * @author peng-yongsheng + */ +@Getter +@Setter +public class EndpointInfo { + private int id; + private String name; + private int serviceId; + private String serviceName; +} diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetadataQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetadataQuery.java index 3ab69c1adb7a0f97a37f326b611e4e257bb31d66..4203eb2a43bc87806c4b6ac627af56f4b464029b 100644 --- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetadataQuery.java +++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetadataQuery.java @@ -85,4 +85,8 @@ public class MetadataQuery implements GraphQLQueryResolver { final int limit) throws IOException { return getMetadataQueryService().searchEndpoint(keyword, serviceId, limit); } + + public EndpointInfo getEndpointInfo(final int endpointId) throws IOException { + return getMetadataQueryService().getEndpointInfo(endpointId); + } } diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol b/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol index 3a83be79a9c23aad6576ed2a4a04b82de6d7a829..1122e97b5604ae96447bd58ecdb248d7e02952aa 160000 --- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol +++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol @@ -1 +1 @@ -Subproject commit 3a83be79a9c23aad6576ed2a4a04b82de6d7a829 +Subproject commit 1122e97b5604ae96447bd58ecdb248d7e02952aa 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 07b6dd5f8c7f8e7f806f78c7591f70f7df1b39fd..0be8502b94432a631028cb78d420ca6ab6552a08 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 @@ -25,8 +25,7 @@ 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.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.library.util.*; import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.*; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.search.SearchResponse; @@ -158,7 +157,7 @@ public class MetadataQueryEsDAO extends EsDAO implements IMetadataQueryDAO { Map sourceAsMap = searchHit.getSourceAsMap(); Endpoint endpoint = new Endpoint(); - endpoint.setId(String.valueOf(sourceAsMap.get(EndpointInventory.SEQUENCE))); + endpoint.setId(((Number)sourceAsMap.get(EndpointInventory.SEQUENCE)).intValue()); endpoint.setName((String)sourceAsMap.get(EndpointInventory.NAME)); endpoints.add(endpoint); }