提交 4c04a599 编写于 作者: P peng-yongsheng

All of the inventory register test success.

上级 50ec820f
...@@ -125,11 +125,11 @@ public class SpringSleuthSegmentBuilderTest implements SegmentListener { ...@@ -125,11 +125,11 @@ public class SpringSleuthSegmentBuilderTest implements SegmentListener {
private List<Span> buildSpringSleuthExampleTrace() throws UnsupportedEncodingException { private List<Span> buildSpringSleuthExampleTrace() throws UnsupportedEncodingException {
List<Span> spans = new LinkedList<>(); List<Span> spans = new LinkedList<>();
String span = "{\"traceId\":\"5b0e64354eea4fa71a8a1b5bdd791b8a\",\"id\":\"1a8a1b5bdd791b8a\",\"kind\":\"SERVER\",\"name\":\"get /\",\"timestamp\":1527669813700123,\"duration\":11295,\"localEndpoint\":{\"serviceName\":\"frontend\",\"ipv4\":\"192.168.72.220\"},\"remoteEndpoint\":{\"ipv6\":\"::1\",\"port\":55146},\"tags\":{\"http.method\":\"GET\",\"http.path\":\"/\",\"mvc.controller.class\":\"Frontend\",\"mvc.controller.method\":\"callBackend\"}}"; String span = "{\"traceId\":\"5b0e64354eea4fa71a8a1b5bdd791b8a\",\"id\":\"1a8a1b5bdd791b8a\",\"kind\":\"SERVER\",\"name\":\"get /\",\"timestamp\":1527669813700123,\"duration\":11295,\"localEndpoint\":{\"serviceName\":\"frontend\",\"ipv4s\":\"192.168.72.220\"},\"remoteEndpoint\":{\"ipv6\":\"::1\",\"port\":55146},\"tags\":{\"http.method\":\"GET\",\"http.path\":\"/\",\"mvc.controller.class\":\"Frontend\",\"mvc.controller.method\":\"callBackend\"}}";
spans.add(SpanBytesDecoder.JSON_V2.decodeOne(span.getBytes("UTF-8"))); spans.add(SpanBytesDecoder.JSON_V2.decodeOne(span.getBytes("UTF-8")));
span = "{\"traceId\":\"5b0e64354eea4fa71a8a1b5bdd791b8a\",\"parentId\":\"1a8a1b5bdd791b8a\",\"id\":\"d7d5b93dcda767c8\",\"kind\":\"CLIENT\",\"name\":\"get\",\"timestamp\":1527669813702456,\"duration\":6672,\"localEndpoint\":{\"serviceName\":\"frontend\",\"ipv4\":\"192.168.72.220\"},\"tags\":{\"http.method\":\"GET\",\"http.path\":\"/api\"}}"; span = "{\"traceId\":\"5b0e64354eea4fa71a8a1b5bdd791b8a\",\"parentId\":\"1a8a1b5bdd791b8a\",\"id\":\"d7d5b93dcda767c8\",\"kind\":\"CLIENT\",\"name\":\"get\",\"timestamp\":1527669813702456,\"duration\":6672,\"localEndpoint\":{\"serviceName\":\"frontend\",\"ipv4s\":\"192.168.72.220\"},\"tags\":{\"http.method\":\"GET\",\"http.path\":\"/api\"}}";
spans.add(SpanBytesDecoder.JSON_V2.decodeOne(span.getBytes("UTF-8"))); spans.add(SpanBytesDecoder.JSON_V2.decodeOne(span.getBytes("UTF-8")));
span = "{\"traceId\":\"5b0e64354eea4fa71a8a1b5bdd791b8a\",\"parentId\":\"1a8a1b5bdd791b8a\",\"id\":\"d7d5b93dcda767c8\",\"kind\":\"SERVER\",\"name\":\"get /api\",\"timestamp\":1527669813705106,\"duration\":4802,\"localEndpoint\":{\"serviceName\":\"backend\",\"ipv4\":\"192.168.72.220\"},\"remoteEndpoint\":{\"ipv4\":\"127.0.0.1\",\"port\":55147},\"tags\":{\"http.method\":\"GET\",\"http.path\":\"/api\",\"mvc.controller.class\":\"Backend\",\"mvc.controller.method\":\"printDate\"},\"shared\":true}"; span = "{\"traceId\":\"5b0e64354eea4fa71a8a1b5bdd791b8a\",\"parentId\":\"1a8a1b5bdd791b8a\",\"id\":\"d7d5b93dcda767c8\",\"kind\":\"SERVER\",\"name\":\"get /api\",\"timestamp\":1527669813705106,\"duration\":4802,\"localEndpoint\":{\"serviceName\":\"backend\",\"ipv4s\":\"192.168.72.220\"},\"remoteEndpoint\":{\"ipv4s\":\"127.0.0.1\",\"port\":55147},\"tags\":{\"http.method\":\"GET\",\"http.path\":\"/api\",\"mvc.controller.class\":\"Backend\",\"mvc.controller.method\":\"printDate\"},\"shared\":true}";
spans.add(SpanBytesDecoder.JSON_V2.decodeOne(span.getBytes("UTF-8"))); spans.add(SpanBytesDecoder.JSON_V2.decodeOne(span.getBytes("UTF-8")));
return SpanBytesDecoder.JSON_V2.decodeList(spans.toString().getBytes("UTF-8")); return SpanBytesDecoder.JSON_V2.decodeList(spans.toString().getBytes("UTF-8"));
......
...@@ -57,7 +57,7 @@ public class ContextCarrier implements Serializable { ...@@ -57,7 +57,7 @@ public class ContextCarrier implements Serializable {
private int entryApplicationInstanceId = DictionaryUtil.nullValue(); private int entryApplicationInstanceId = DictionaryUtil.nullValue();
/** /**
* peer(ipv4/ipv6/hostname + port) of the server, from client side. * peer(ipv4s/ipv6/hostname + port) of the server, from client side.
*/ */
private String peerHost; private String peerHost;
......
...@@ -52,18 +52,18 @@ public class EndpointInventoryCache implements Service { ...@@ -52,18 +52,18 @@ public class EndpointInventoryCache implements Service {
} }
return cacheDAO; return cacheDAO;
} }
public int getEndpointId(int serviceId, String endpointName) { public int getEndpointId(int serviceId, String endpointName) {
String id = EndpointInventory.buildId(serviceId, endpointName); String id = EndpointInventory.buildId(serviceId, endpointName);
int endpointId = Const.NONE; int endpointId = Const.NONE;
try { try {
endpointId = endpointNameCache.get(EndpointInventory.buildId(serviceId, endpointName), () -> getCacheDAO().getEndpointId(serviceId, endpointName)); endpointId = endpointNameCache.get(id, () -> getCacheDAO().getEndpointId(serviceId, endpointName));
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
if (serviceId == Const.NONE) { if (endpointId == Const.NONE) {
endpointId = getCacheDAO().getEndpointId(serviceId, endpointName); endpointId = getCacheDAO().getEndpointId(serviceId, endpointName);
if (endpointId != Const.NONE) { if (endpointId != Const.NONE) {
endpointNameCache.put(id, endpointId); endpointNameCache.put(id, endpointId);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.skywalking.oap.server.core.cache; package org.apache.skywalking.oap.server.core.cache;
import com.google.common.cache.*; import com.google.common.cache.*;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.ServiceInventory; import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.storage.StorageModule; import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.cache.IServiceInventoryCacheDAO; import org.apache.skywalking.oap.server.core.storage.cache.IServiceInventoryCacheDAO;
...@@ -53,16 +54,16 @@ public class ServiceInventoryCache implements Service { ...@@ -53,16 +54,16 @@ public class ServiceInventoryCache implements Service {
} }
public int getServiceId(String serviceName) { public int getServiceId(String serviceName) {
int serviceId = 0; int serviceId = Const.NONE;
try { try {
serviceId = serviceNameCache.get(ServiceInventory.buildId(serviceName), () -> getCacheDAO().getServiceId(serviceName)); serviceId = serviceNameCache.get(ServiceInventory.buildId(serviceName), () -> getCacheDAO().getServiceId(serviceName));
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
if (serviceId == 0) { if (serviceId == Const.NONE) {
serviceId = getCacheDAO().getServiceId(serviceName); serviceId = getCacheDAO().getServiceId(serviceName);
if (serviceId != 0) { if (serviceId != Const.NONE) {
serviceNameCache.put(ServiceInventory.buildId(serviceName), serviceId); serviceNameCache.put(ServiceInventory.buildId(serviceName), serviceId);
} }
} }
...@@ -70,16 +71,16 @@ public class ServiceInventoryCache implements Service { ...@@ -70,16 +71,16 @@ public class ServiceInventoryCache implements Service {
} }
public int getServiceId(int addressId) { public int getServiceId(int addressId) {
int serviceId = 0; int serviceId = Const.NONE;
try { try {
serviceId = addressIdCache.get(ServiceInventory.buildId(addressId), () -> getCacheDAO().getServiceId(addressId)); serviceId = addressIdCache.get(ServiceInventory.buildId(addressId), () -> getCacheDAO().getServiceId(addressId));
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
if (serviceId == 0) { if (serviceId == Const.NONE) {
serviceId = getCacheDAO().getServiceId(addressId); serviceId = getCacheDAO().getServiceId(addressId);
if (serviceId != 0) { if (serviceId != Const.NONE) {
addressIdCache.put(ServiceInventory.buildId(addressId), serviceId); addressIdCache.put(ServiceInventory.buildId(addressId), serviceId);
} }
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.skywalking.oap.server.core.register; package org.apache.skywalking.oap.server.core.register;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.util.*; import java.util.*;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
...@@ -40,13 +42,13 @@ public class ServiceInstanceInventory extends RegisterSource { ...@@ -40,13 +42,13 @@ public class ServiceInstanceInventory extends RegisterSource {
public static final String MODEL_NAME = "service_instance_inventory"; public static final String MODEL_NAME = "service_instance_inventory";
public static final String NAME = "name"; public static final String NAME = "name";
public static final String SERVICE_ID = "service_id"; private static final String SERVICE_ID = "service_id";
public static final String IS_ADDRESS = "is_address"; private static final String IS_ADDRESS = "is_address";
public static final String ADDRESS_ID = "address_id"; private static final String ADDRESS_ID = "address_id";
private static final String OS_NAME = "os_name"; private static final String OS_NAME = "os_name";
private static final String HOST_NAME = "host_name"; private static final String HOST_NAME = "host_name";
private static final String PROCESS_NO = "process_no"; private static final String PROCESS_NO = "process_no";
private static final String IPV4 = "ipv4"; private static final String IPV4S = "ipv4s";
@Setter @Getter @Column(columnName = NAME, matchQuery = true) private String name = Const.EMPTY_STRING; @Setter @Getter @Column(columnName = NAME, matchQuery = true) private String name = Const.EMPTY_STRING;
@Setter @Getter @Column(columnName = SERVICE_ID) private int serviceId; @Setter @Getter @Column(columnName = SERVICE_ID) private int serviceId;
...@@ -55,7 +57,7 @@ public class ServiceInstanceInventory extends RegisterSource { ...@@ -55,7 +57,7 @@ public class ServiceInstanceInventory extends RegisterSource {
@Setter @Getter @Column(columnName = OS_NAME) private String osName; @Setter @Getter @Column(columnName = OS_NAME) private String osName;
@Setter @Getter @Column(columnName = HOST_NAME) private String hostName; @Setter @Getter @Column(columnName = HOST_NAME) private String hostName;
@Setter @Getter @Column(columnName = PROCESS_NO) private int processNo; @Setter @Getter @Column(columnName = PROCESS_NO) private int processNo;
@Setter @Getter @Column(columnName = IPV4) private String ipv4; @Setter @Getter @Column(columnName = IPV4S) private String ipv4s;
public static String buildId(int serviceId, String serviceInstanceName) { public static String buildId(int serviceId, String serviceInstanceName) {
return serviceId + Const.ID_SPLIT + serviceInstanceName + Const.ID_SPLIT + BooleanUtils.FALSE + Const.ID_SPLIT + Const.NONE; return serviceId + Const.ID_SPLIT + serviceInstanceName + Const.ID_SPLIT + BooleanUtils.FALSE + Const.ID_SPLIT + Const.NONE;
...@@ -117,7 +119,7 @@ public class ServiceInstanceInventory extends RegisterSource { ...@@ -117,7 +119,7 @@ public class ServiceInstanceInventory extends RegisterSource {
remoteBuilder.setDataStrings(0, name); remoteBuilder.setDataStrings(0, name);
remoteBuilder.setDataStrings(1, osName); remoteBuilder.setDataStrings(1, osName);
remoteBuilder.setDataStrings(2, hostName); remoteBuilder.setDataStrings(2, hostName);
remoteBuilder.setDataStrings(3, ipv4); remoteBuilder.setDataStrings(3, ipv4s);
return remoteBuilder; return remoteBuilder;
} }
...@@ -134,7 +136,7 @@ public class ServiceInstanceInventory extends RegisterSource { ...@@ -134,7 +136,7 @@ public class ServiceInstanceInventory extends RegisterSource {
setName(remoteData.getDataStrings(0)); setName(remoteData.getDataStrings(0));
setOsName(remoteData.getDataStrings(1)); setOsName(remoteData.getDataStrings(1));
setHostName(remoteData.getDataStrings(2)); setHostName(remoteData.getDataStrings(2));
setIpv4(remoteData.getDataStrings(3)); setIpv4s(remoteData.getDataStrings(3));
} }
public static class Builder implements StorageBuilder<ServiceInstanceInventory> { public static class Builder implements StorageBuilder<ServiceInstanceInventory> {
...@@ -153,7 +155,7 @@ public class ServiceInstanceInventory extends RegisterSource { ...@@ -153,7 +155,7 @@ public class ServiceInstanceInventory extends RegisterSource {
inventory.setName((String)dbMap.get(NAME)); inventory.setName((String)dbMap.get(NAME));
inventory.setOsName((String)dbMap.get(OS_NAME)); inventory.setOsName((String)dbMap.get(OS_NAME));
inventory.setHostName((String)dbMap.get(HOST_NAME)); inventory.setHostName((String)dbMap.get(HOST_NAME));
inventory.setIpv4((String)dbMap.get(IPV4)); inventory.setIpv4s((String)dbMap.get(IPV4S));
return inventory; return inventory;
} }
...@@ -171,8 +173,30 @@ public class ServiceInstanceInventory extends RegisterSource { ...@@ -171,8 +173,30 @@ public class ServiceInstanceInventory extends RegisterSource {
map.put(NAME, storageData.getName()); map.put(NAME, storageData.getName());
map.put(OS_NAME, storageData.getOsName()); map.put(OS_NAME, storageData.getOsName());
map.put(HOST_NAME, storageData.getHostName()); map.put(HOST_NAME, storageData.getHostName());
map.put(IPV4, storageData.getIpv4()); map.put(IPV4S, storageData.getIpv4s());
return map; return map;
} }
} }
public static class AgentOsInfo {
@Setter @Getter private String osName;
@Setter @Getter private String hostname;
@Setter @Getter private int processNo;
@Getter private List<String> ipv4s;
public AgentOsInfo() {
this.ipv4s = new ArrayList<>();
}
public static String ipv4sSerialize(List<String> ipv4) {
Gson gson = new Gson();
return gson.toJson(ipv4);
}
public static List<String> ipv4sDeserialize(String ipv4s) {
Gson gson = new Gson();
return gson.fromJson(ipv4s, new TypeToken<List<String>>() {
}.getType());
}
}
} }
...@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core.register.service; ...@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core.register.service;
import org.apache.skywalking.oap.server.core.*; import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache; import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.register.EndpointInventory; import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.worker.InventoryProcess;
import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.slf4j.*; import org.slf4j.*;
...@@ -59,6 +60,8 @@ public class EndpointInventoryRegister implements IEndpointInventoryRegister { ...@@ -59,6 +60,8 @@ public class EndpointInventoryRegister implements IEndpointInventoryRegister {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
endpointInventory.setRegisterTime(now); endpointInventory.setRegisterTime(now);
endpointInventory.setHeartbeatTime(now); endpointInventory.setHeartbeatTime(now);
InventoryProcess.INSTANCE.in(endpointInventory);
} }
return endpointId; return endpointId;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.server.core.register.service; package org.apache.skywalking.oap.server.core.register.service;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.library.module.Service; import org.apache.skywalking.oap.server.library.module.Service;
/** /**
...@@ -25,7 +26,8 @@ import org.apache.skywalking.oap.server.library.module.Service; ...@@ -25,7 +26,8 @@ import org.apache.skywalking.oap.server.library.module.Service;
*/ */
public interface IServiceInstanceInventoryRegister extends Service { public interface IServiceInstanceInventoryRegister extends Service {
int getOrCreate(int serviceId, String serviceInstanceName, long registerTime); int getOrCreate(int serviceId, String serviceInstanceName, long registerTime,
ServiceInstanceInventory.AgentOsInfo osInfo);
int getOrCreate(int serviceId, int addressId, long registerTime); int getOrCreate(int serviceId, int addressId, long registerTime);
} }
...@@ -81,6 +81,7 @@ public class NetworkAddressInventoryRegister implements INetworkAddressInventory ...@@ -81,6 +81,7 @@ public class NetworkAddressInventoryRegister implements INetworkAddressInventory
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
newNetworkAddress.setRegisterTime(now); newNetworkAddress.setRegisterTime(now);
newNetworkAddress.setHeartbeatTime(now); newNetworkAddress.setHeartbeatTime(now);
InventoryProcess.INSTANCE.in(newNetworkAddress); InventoryProcess.INSTANCE.in(newNetworkAddress);
} }
......
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
package org.apache.skywalking.oap.server.core.register.service; package org.apache.skywalking.oap.server.core.register.service;
import org.apache.skywalking.oap.server.core.*; import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory; import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.worker.InventoryProcess; import org.apache.skywalking.oap.server.core.register.worker.InventoryProcess;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.cache.IServiceInstanceInventoryCacheDAO; import org.apache.skywalking.oap.server.core.storage.cache.IServiceInstanceInventoryCacheDAO;
import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.util.BooleanUtils; import org.apache.skywalking.oap.server.library.util.BooleanUtils;
...@@ -44,12 +45,13 @@ public class ServiceInstanceInventoryRegister implements IServiceInstanceInvento ...@@ -44,12 +45,13 @@ public class ServiceInstanceInventoryRegister implements IServiceInstanceInvento
private IServiceInstanceInventoryCacheDAO getCacheDAO() { private IServiceInstanceInventoryCacheDAO getCacheDAO() {
if (isNull(cacheDAO)) { if (isNull(cacheDAO)) {
cacheDAO = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryCacheDAO.class); cacheDAO = moduleManager.find(StorageModule.NAME).getService(IServiceInstanceInventoryCacheDAO.class);
} }
return cacheDAO; return cacheDAO;
} }
@Override public int getOrCreate(int serviceId, String serviceInstanceName, long registerTime) { @Override public int getOrCreate(int serviceId, String serviceInstanceName, long registerTime,
ServiceInstanceInventory.AgentOsInfo osInfo) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Get or create service instance by service instance name, service id: {}, service instance name: {}, registerTime: {}", serviceId, serviceInstanceName, registerTime); logger.debug("Get or create service instance by service instance name, service id: {}, service instance name: {}, registerTime: {}", serviceId, serviceInstanceName, registerTime);
} }
...@@ -66,6 +68,11 @@ public class ServiceInstanceInventoryRegister implements IServiceInstanceInvento ...@@ -66,6 +68,11 @@ public class ServiceInstanceInventoryRegister implements IServiceInstanceInvento
serviceInstanceInventory.setRegisterTime(registerTime); serviceInstanceInventory.setRegisterTime(registerTime);
serviceInstanceInventory.setHeartbeatTime(registerTime); serviceInstanceInventory.setHeartbeatTime(registerTime);
serviceInstanceInventory.setOsName(osInfo.getOsName());
serviceInstanceInventory.setHostName(osInfo.getHostname());
serviceInstanceInventory.setProcessNo(osInfo.getProcessNo());
serviceInstanceInventory.setIpv4s(ServiceInstanceInventory.AgentOsInfo.ipv4sSerialize(osInfo.getIpv4s()));
InventoryProcess.INSTANCE.in(serviceInstanceInventory); InventoryProcess.INSTANCE.in(serviceInstanceInventory);
} }
return serviceInstanceId; return serviceInstanceId;
......
...@@ -47,7 +47,9 @@ public class RegisterModuleProvider extends ModuleProvider { ...@@ -47,7 +47,9 @@ public class RegisterModuleProvider extends ModuleProvider {
@Override public void start() { @Override public void start() {
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class); GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class);
grpcHandlerRegister.addHandler(new ApplicationRegisterHandler(getManager())); grpcHandlerRegister.addHandler(new ApplicationRegisterHandler(getManager()));
grpcHandlerRegister.addHandler(new InstanceDiscoveryServiceHandler(getManager()));
grpcHandlerRegister.addHandler(new ServiceNameDiscoveryHandler(getManager())); grpcHandlerRegister.addHandler(new ServiceNameDiscoveryHandler(getManager()));
grpcHandlerRegister.addHandler(new NetworkAddressRegisterServiceHandler(getManager()));
} }
@Override public void notifyAfterCompleted() { @Override public void notifyAfterCompleted() {
......
...@@ -42,7 +42,7 @@ public class ApplicationRegisterHandler extends ApplicationRegisterServiceGrpc.A ...@@ -42,7 +42,7 @@ public class ApplicationRegisterHandler extends ApplicationRegisterServiceGrpc.A
@Override @Override
public void applicationCodeRegister(Application request, StreamObserver<ApplicationMapping> responseObserver) { public void applicationCodeRegister(Application request, StreamObserver<ApplicationMapping> responseObserver) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("register application"); logger.debug("Register application, application code: {}", request.getApplicationCode());
} }
ApplicationMapping.Builder builder = ApplicationMapping.newBuilder(); ApplicationMapping.Builder builder = ApplicationMapping.newBuilder();
......
/*
* 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.receiver.register.provider.handler.v5;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
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.grpc.GRPCHandler;
import org.slf4j.*;
/**
* @author peng-yongsheng
*/
public class InstanceDiscoveryServiceHandler extends InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceImplBase implements GRPCHandler {
private static final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServiceHandler.class);
private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
// private final IInstanceHeartBeatService instanceHeartBeatService;
public InstanceDiscoveryServiceHandler(ModuleManager moduleManager) {
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
// this.instanceHeartBeatService = moduleManager.find(CoreModule.NAME).getService(IInstanceHeartBeatService.class);
}
@Override
public void registerInstance(ApplicationInstance request,
StreamObserver<ApplicationInstanceMapping> responseObserver) {
OSInfo osinfo = request.getOsinfo();
ServiceInstanceInventory.AgentOsInfo agentOsInfo = new ServiceInstanceInventory.AgentOsInfo();
agentOsInfo.setHostname(osinfo.getHostname());
agentOsInfo.setOsName(osinfo.getOsName());
agentOsInfo.setProcessNo(osinfo.getProcessNo());
agentOsInfo.getIpv4s().addAll(osinfo.getIpv4SList());
int serviceInstanceId = serviceInstanceInventoryRegister.getOrCreate(request.getApplicationId(), request.getAgentUUID(), request.getRegisterTime(), agentOsInfo);
ApplicationInstanceMapping.Builder builder = ApplicationInstanceMapping.newBuilder();
builder.setApplicationId(request.getApplicationId());
builder.setApplicationInstanceId(serviceInstanceId);
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}
@Override public void heartbeat(ApplicationInstanceHeartbeat request, StreamObserver<Downstream> responseObserver) {
// int instanceId = request.getApplicationInstanceId();
// long heartBeatTime = request.getHeartbeatTime();
// this.instanceHeartBeatService.heartBeat(instanceId, heartBeatTime);
// responseObserver.onNext(Downstream.getDefaultInstance());
// responseObserver.onCompleted();
}
}
/*
* 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.receiver.register.provider.handler.v5;
import com.google.protobuf.ProtocolStringList;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.slf4j.*;
/**
* @author peng-yongsheng
*/
public class NetworkAddressRegisterServiceHandler extends NetworkAddressRegisterServiceGrpc.NetworkAddressRegisterServiceImplBase implements GRPCHandler {
private static final Logger logger = LoggerFactory.getLogger(NetworkAddressRegisterServiceHandler.class);
private final INetworkAddressInventoryRegister networkAddressInventoryRegister;
public NetworkAddressRegisterServiceHandler(ModuleManager moduleManager) {
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).getService(INetworkAddressInventoryRegister.class);
}
@Override
public void batchRegister(NetworkAddresses request, StreamObserver<NetworkAddressMappings> responseObserver) {
if (logger.isDebugEnabled()) {
logger.debug("register application");
}
ProtocolStringList addressesList = request.getAddressesList();
NetworkAddressMappings.Builder builder = NetworkAddressMappings.newBuilder();
for (String networkAddress : addressesList) {
int addressId = networkAddressInventoryRegister.getOrCreate(networkAddress);
if (addressId != Const.NONE) {
KeyWithIntegerValue value = KeyWithIntegerValue.newBuilder().setKey(networkAddress).setValue(addressId).build();
builder.addAddressIds(value);
}
}
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}
}
...@@ -38,6 +38,6 @@ public class ApplicationRegisterHandlerTestCase { ...@@ -38,6 +38,6 @@ public class ApplicationRegisterHandlerTestCase {
application.setApplicationCode("dubbox-consumer"); application.setApplicationCode("dubbox-consumer");
ApplicationMapping applicationMapping = stub.applicationCodeRegister(application.build()); ApplicationMapping applicationMapping = stub.applicationCodeRegister(application.build());
logger.debug("application id: {}", applicationMapping.getApplication().getValue()); logger.info("application id: {}", applicationMapping.getApplication().getValue());
} }
} }
/*
* 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.receiver.register.provider.handler.v5;
import io.grpc.*;
import org.apache.skywalking.apm.network.language.agent.*;
import org.slf4j.*;
/**
* @author peng-yongsheng
*/
public class InstanceDiscoveryServiceHandlerTestCase {
private static final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServiceHandlerTestCase.class);
public static void main(String[] args) {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceBlockingStub stub = InstanceDiscoveryServiceGrpc.newBlockingStub(channel);
ApplicationInstance.Builder applicationInstance = ApplicationInstance.newBuilder();
applicationInstance.setApplicationId(1);
applicationInstance.setAgentUUID("Test");
applicationInstance.setRegisterTime(System.currentTimeMillis());
OSInfo.Builder osInfo = OSInfo.newBuilder();
osInfo.setOsName("mac os");
osInfo.setHostname("pengys");
osInfo.setProcessNo(1);
osInfo.addIpv4S("10.0.0.1");
osInfo.addIpv4S("10.0.0.2");
applicationInstance.setOsinfo(osInfo);
ApplicationInstanceMapping instanceMapping = stub.registerInstance(applicationInstance.build());
logger.info("application id: {}, application instance id: {}", instanceMapping.getApplicationId(), instanceMapping.getApplicationInstanceId());
}
}
/*
* 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.receiver.register.provider.handler.v5;
import io.grpc.*;
import org.apache.skywalking.apm.network.language.agent.*;
import org.slf4j.*;
/**
* @author peng-yongsheng
*/
public class NetworkAddressRegisterServiceHandlerTestCase {
private static final Logger logger = LoggerFactory.getLogger(NetworkAddressRegisterServiceHandlerTestCase.class);
public static void main(String[] args) {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
NetworkAddressRegisterServiceGrpc.NetworkAddressRegisterServiceBlockingStub stub = NetworkAddressRegisterServiceGrpc.newBlockingStub(channel);
NetworkAddresses.Builder networkAddresses = NetworkAddresses.newBuilder();
networkAddresses.addAddresses("127.0.0.1:8080");
NetworkAddressMappings addressMappings = stub.batchRegister(networkAddresses.build());
for (KeyWithIntegerValue value : addressMappings.getAddressIdsList()) {
logger.info("key: {}, value: {}", value.getKey(), value.getValue());
}
}
}
...@@ -41,8 +41,9 @@ public class ServiceNameDiscoveryHandlerTestCase { ...@@ -41,8 +41,9 @@ public class ServiceNameDiscoveryHandlerTestCase {
serviceNameCollection.addElements(serviceNameElement); serviceNameCollection.addElements(serviceNameElement);
ServiceNameMappingCollection collection = stub.discovery(serviceNameCollection.build()); ServiceNameMappingCollection collection = stub.discovery(serviceNameCollection.build());
for (ServiceNameMappingElement element : collection.getElementsList()) { for (ServiceNameMappingElement element : collection.getElementsList()) {
logger.debug("service id: {}", element.getServiceId()); logger.info("service id: {}", element.getServiceId());
} }
} }
} }
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
~ ~
--> -->
<Configuration status="DEBUG"> <Configuration status="INFO">
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_OUT"> <Console name="Console" target="SYSTEM_OUT">
<PatternLayout charset="UTF-8" pattern="%d - %c -%-4r [%t] %-5p %x - %m%n"/> <PatternLayout charset="UTF-8" pattern="%d - %c -%-4r [%t] %-5p %x - %m%n"/>
</Console> </Console>
</Appenders> </Appenders>
<Loggers> <Loggers>
<Root level="DEBUG"> <Root level="INFO">
<AppenderRef ref="Console"/> <AppenderRef ref="Console"/>
</Root> </Root>
</Loggers> </Loggers>
......
...@@ -33,7 +33,7 @@ public class ColumnTypeEsMapping implements DataTypeMapping { ...@@ -33,7 +33,7 @@ public class ColumnTypeEsMapping implements DataTypeMapping {
} else if (Double.class.equals(type) || double.class.equals(type)) { } else if (Double.class.equals(type) || double.class.equals(type)) {
return "double"; return "double";
} else if (String.class.equals(type)) { } else if (String.class.equals(type)) {
return "text"; return "keyword";
} else { } else {
throw new IllegalArgumentException("Unsupported data type: " + type.getName()); throw new IllegalArgumentException("Unsupported data type: " + type.getName());
} }
......
...@@ -48,7 +48,7 @@ public class EndpointInventoryCacheEsDAO extends EsDAO implements IEndpointInven ...@@ -48,7 +48,7 @@ public class EndpointInventoryCacheEsDAO extends EsDAO implements IEndpointInven
String id = EndpointInventory.buildId(serviceId, endpointName); String id = EndpointInventory.buildId(serviceId, endpointName);
GetResponse response = getClient().get(EndpointInventory.MODEL_NAME, id); GetResponse response = getClient().get(EndpointInventory.MODEL_NAME, id);
if (response.isExists()) { if (response.isExists()) {
return response.getField(RegisterSource.SEQUENCE).getValue(); return (int)response.getSource().getOrDefault(RegisterSource.SEQUENCE, 0);
} else { } else {
return Const.NONE; return Const.NONE;
} }
......
...@@ -48,7 +48,7 @@ public class NetworkAddressInventoryCacheEsDAO extends EsDAO implements INetwork ...@@ -48,7 +48,7 @@ public class NetworkAddressInventoryCacheEsDAO extends EsDAO implements INetwork
String id = NetworkAddressInventory.buildId(networkAddress); String id = NetworkAddressInventory.buildId(networkAddress);
GetResponse response = getClient().get(NetworkAddressInventory.MODEL_NAME, id); GetResponse response = getClient().get(NetworkAddressInventory.MODEL_NAME, id);
if (response.isExists()) { if (response.isExists()) {
return response.getField(RegisterSource.SEQUENCE).getValue(); return (int)response.getSource().getOrDefault(RegisterSource.SEQUENCE, 0);
} else { } else {
return Const.NONE; return Const.NONE;
} }
......
...@@ -76,7 +76,7 @@ public class ServiceInstanceInventoryCacheDAO extends EsDAO implements IServiceI ...@@ -76,7 +76,7 @@ public class ServiceInstanceInventoryCacheDAO extends EsDAO implements IServiceI
try { try {
GetResponse response = getClient().get(ServiceInstanceInventory.MODEL_NAME, id); GetResponse response = getClient().get(ServiceInstanceInventory.MODEL_NAME, id);
if (response.isExists()) { if (response.isExists()) {
return response.getField(RegisterSource.SEQUENCE).getValue(); return (int)response.getSource().getOrDefault(RegisterSource.SEQUENCE, 0);
} else { } else {
return Const.NONE; return Const.NONE;
} }
......
...@@ -57,7 +57,7 @@ public class ServiceInventoryCacheEsDAO extends EsDAO implements IServiceInvento ...@@ -57,7 +57,7 @@ public class ServiceInventoryCacheEsDAO extends EsDAO implements IServiceInvento
try { try {
GetResponse response = getClient().get(ServiceInventory.MODEL_NAME, id); GetResponse response = getClient().get(ServiceInventory.MODEL_NAME, id);
if (response.isExists()) { if (response.isExists()) {
return response.getField(RegisterSource.SEQUENCE).getValue(); return (int)response.getSource().getOrDefault(RegisterSource.SEQUENCE, 0);
} else { } else {
return Const.NONE; return Const.NONE;
} }
......
...@@ -48,6 +48,7 @@ public class RegisterLockInstaller { ...@@ -48,6 +48,7 @@ public class RegisterLockInstaller {
putIfAbsent(Scope.Endpoint.ordinal()); putIfAbsent(Scope.Endpoint.ordinal());
putIfAbsent(Scope.ServiceInstance.ordinal()); putIfAbsent(Scope.ServiceInstance.ordinal());
putIfAbsent(Scope.Service.ordinal()); putIfAbsent(Scope.Service.ordinal());
putIfAbsent(Scope.NetworkAddress.ordinal());
} catch (IOException e) { } catch (IOException e) {
throw new StorageException(e.getMessage()); throw new StorageException(e.getMessage());
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册