You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/10/16 08:22:17 UTC

[GitHub] peng-yongsheng closed pull request #1774: Provide rest protocol for register and trace receiver.

peng-yongsheng closed pull request #1774: Provide rest protocol for register and trace receiver.
URL: https://github.com/apache/incubator-skywalking/pull/1774
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/RegisterModuleProvider.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/RegisterModuleProvider.java
index 6a1706a24..6a1014146 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/RegisterModuleProvider.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/RegisterModuleProvider.java
@@ -19,10 +19,11 @@
 package org.apache.skywalking.oap.server.receiver.register.provider;
 
 import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
+import org.apache.skywalking.oap.server.core.server.*;
 import org.apache.skywalking.oap.server.library.module.*;
 import org.apache.skywalking.oap.server.receiver.register.module.RegisterModule;
-import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.*;
+import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc.*;
+import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest.*;
 
 /**
  * @author peng-yongsheng
@@ -50,6 +51,13 @@
         grpcHandlerRegister.addHandler(new InstanceDiscoveryServiceHandler(getManager()));
         grpcHandlerRegister.addHandler(new ServiceNameDiscoveryHandler(getManager()));
         grpcHandlerRegister.addHandler(new NetworkAddressRegisterServiceHandler(getManager()));
+
+        JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).getService(JettyHandlerRegister.class);
+        jettyHandlerRegister.addHandler(new ApplicationRegisterServletHandler(getManager()));
+        jettyHandlerRegister.addHandler(new InstanceDiscoveryServletHandler(getManager()));
+        jettyHandlerRegister.addHandler(new InstanceHeartBeatServletHandler(getManager()));
+        jettyHandlerRegister.addHandler(new NetworkAddressRegisterServletHandler(getManager()));
+        jettyHandlerRegister.addHandler(new ServiceNameDiscoveryServiceHandler(getManager()));
     }
 
     @Override public void notifyAfterCompleted() {
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/ApplicationRegisterHandler.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/ApplicationRegisterHandler.java
similarity index 99%
rename from oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/ApplicationRegisterHandler.java
rename to oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/ApplicationRegisterHandler.java
index ea698bc14..224a2c2b3 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/ApplicationRegisterHandler.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/ApplicationRegisterHandler.java
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
+package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
 
 import io.grpc.stub.StreamObserver;
 import org.apache.skywalking.apm.network.language.agent.*;
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/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
similarity index 99%
rename from oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/InstanceDiscoveryServiceHandler.java
rename to 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 11681f145..4b12f8567 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/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
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
+package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
 
 import io.grpc.stub.StreamObserver;
 import org.apache.skywalking.apm.network.language.agent.*;
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/NetworkAddressRegisterServiceHandler.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/NetworkAddressRegisterServiceHandler.java
similarity index 99%
rename from oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/NetworkAddressRegisterServiceHandler.java
rename to oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/NetworkAddressRegisterServiceHandler.java
index 6df497b59..023d6c689 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/NetworkAddressRegisterServiceHandler.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/NetworkAddressRegisterServiceHandler.java
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
+package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
 
 import com.google.protobuf.ProtocolStringList;
 import io.grpc.stub.StreamObserver;
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/ServiceNameDiscoveryHandler.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/ServiceNameDiscoveryHandler.java
similarity index 99%
rename from oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/ServiceNameDiscoveryHandler.java
rename to oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/ServiceNameDiscoveryHandler.java
index 93ddbdc41..ae531e27e 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/ServiceNameDiscoveryHandler.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/ServiceNameDiscoveryHandler.java
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5;
+package org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc;
 
 import io.grpc.stub.StreamObserver;
 import java.util.List;
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/ApplicationRegisterServletHandler.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/ApplicationRegisterServletHandler.java
new file mode 100644
index 000000000..edc551a9b
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/ApplicationRegisterServletHandler.java
@@ -0,0 +1,71 @@
+/*
+ * 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.rest;
+
+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.register.service.IServiceInventoryRegister;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.server.jetty.*;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class ApplicationRegisterServletHandler extends JettyJsonHandler {
+
+    private static final Logger logger = LoggerFactory.getLogger(ApplicationRegisterServletHandler.class);
+
+    private final IServiceInventoryRegister serviceInventoryRegister;
+    private Gson gson = new Gson();
+    private static final String APPLICATION_CODE = "c";
+    private static final String APPLICATION_ID = "i";
+
+    public ApplicationRegisterServletHandler(ModuleManager moduleManager) {
+        serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
+    }
+
+    @Override public String pathSpec() {
+        return "/application/register";
+    }
+
+    @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
+        JsonArray responseArray = new JsonArray();
+        try {
+            JsonArray applicationCodes = gson.fromJson(req.getReader(), JsonArray.class);
+            for (int i = 0; i < applicationCodes.size(); i++) {
+                String applicationCode = applicationCodes.get(i).getAsString();
+                int applicationId = serviceInventoryRegister.getOrCreate(applicationCode);
+                JsonObject mapping = new JsonObject();
+                mapping.addProperty(APPLICATION_CODE, applicationCode);
+                mapping.addProperty(APPLICATION_ID, applicationId);
+                responseArray.add(mapping);
+            }
+        } catch (IOException e) {
+            logger.error(e.getMessage(), e);
+        }
+        return responseArray;
+    }
+}
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
new file mode 100644
index 000000000..c2edc0722
--- /dev/null
+++ 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
@@ -0,0 +1,84 @@
+/*
+ * 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.rest;
+
+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.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.jetty.*;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class InstanceDiscoveryServletHandler extends JettyJsonHandler {
+
+    private static final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServletHandler.class);
+
+    private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
+    private final Gson gson = new Gson();
+
+    private static final String APPLICATION_ID = "ai";
+    private static final String AGENT_UUID = "au";
+    private static final String REGISTER_TIME = "rt";
+    private static final String INSTANCE_ID = "ii";
+    private static final String OS_INFO = "oi";
+
+    public InstanceDiscoveryServletHandler(ModuleManager moduleManager) {
+        this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
+    }
+
+    @Override public String pathSpec() {
+        return "/instance/register";
+    }
+
+    @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
+        JsonObject responseJson = new JsonObject();
+        try {
+            JsonObject instance = gson.fromJson(req.getReader(), JsonObject.class);
+            int applicationId = instance.get(APPLICATION_ID).getAsInt();
+            String agentUUID = instance.get(AGENT_UUID).getAsString();
+            long registerTime = instance.get(REGISTER_TIME).getAsLong();
+            JsonObject osInfoJson = instance.get(OS_INFO).getAsJsonObject();
+
+            ServiceInstanceInventory.AgentOsInfo agentOsInfo = new ServiceInstanceInventory.AgentOsInfo();
+            agentOsInfo.setHostname(osInfoJson.get("osName").getAsString());
+            agentOsInfo.setOsName(osInfoJson.get("hostName").getAsString());
+            agentOsInfo.setProcessNo(osInfoJson.get("processId").getAsInt());
+
+            JsonArray ipv4s = osInfoJson.get("ipv4s").getAsJsonArray();
+            ipv4s.forEach(ipv4 -> agentOsInfo.getIpv4s().add(ipv4.getAsString()));
+
+            int instanceId = serviceInstanceInventoryRegister.getOrCreate(applicationId, agentUUID, registerTime, agentOsInfo);
+            responseJson.addProperty(APPLICATION_ID, applicationId);
+            responseJson.addProperty(INSTANCE_ID, instanceId);
+        } catch (IOException e) {
+            logger.error(e.getMessage(), e);
+        }
+        return responseJson;
+    }
+}
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/InstanceHeartBeatServletHandler.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/InstanceHeartBeatServletHandler.java
new file mode 100644
index 000000000..1c112c74c
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceHeartBeatServletHandler.java
@@ -0,0 +1,68 @@
+/*
+ * 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.rest;
+
+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.register.service.IServiceInstanceInventoryRegister;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.server.jetty.*;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class InstanceHeartBeatServletHandler extends JettyJsonHandler {
+
+    private static final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatServletHandler.class);
+
+    private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
+    private final Gson gson = new Gson();
+
+    private static final String INSTANCE_ID = "ii";
+    private static final String HEARTBEAT_TIME = "ht";
+
+    public InstanceHeartBeatServletHandler(ModuleManager moduleManager) {
+        this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
+    }
+
+    @Override public String pathSpec() {
+        return "/instance/heartbeat";
+    }
+
+    @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException, IOException {
+        JsonObject responseJson = new JsonObject();
+        try {
+            JsonObject heartBeat = gson.fromJson(req.getReader(), JsonObject.class);
+            int instanceId = heartBeat.get(INSTANCE_ID).getAsInt();
+            long heartBeatTime = heartBeat.get(HEARTBEAT_TIME).getAsLong();
+
+            serviceInstanceInventoryRegister.heartbeat(instanceId, heartBeatTime);
+        } catch (IOException e) {
+            logger.error(e.getMessage(), e);
+        }
+        return responseJson;
+    }
+}
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/NetworkAddressRegisterServletHandler.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/NetworkAddressRegisterServletHandler.java
new file mode 100644
index 000000000..41ec38a63
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/NetworkAddressRegisterServletHandler.java
@@ -0,0 +1,76 @@
+/*
+ * 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.rest;
+
+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.register.service.INetworkAddressInventoryRegister;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.server.jetty.JettyJsonHandler;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class NetworkAddressRegisterServletHandler extends JettyJsonHandler {
+
+    private static final Logger logger = LoggerFactory.getLogger(NetworkAddressRegisterServletHandler.class);
+
+    private final INetworkAddressInventoryRegister networkAddressInventoryRegister;
+    private Gson gson = new Gson();
+    private static final String NETWORK_ADDRESS = "n";
+    private static final String ADDRESS_ID = "i";
+
+    public NetworkAddressRegisterServletHandler(ModuleManager moduleManager) {
+        this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).getService(INetworkAddressInventoryRegister.class);
+    }
+
+    @Override public String pathSpec() {
+        return "/networkAddress/register";
+    }
+
+    @Override protected JsonElement doGet(HttpServletRequest req) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override protected JsonElement doPost(HttpServletRequest req) {
+        JsonArray responseArray = new JsonArray();
+        try {
+            JsonArray networkAddresses = gson.fromJson(req.getReader(), JsonArray.class);
+            for (int i = 0; i < networkAddresses.size(); i++) {
+                String networkAddress = networkAddresses.get(i).getAsString();
+
+                if (logger.isDebugEnabled()) {
+                    logger.debug("network address register, network address: {}", networkAddress);
+                }
+
+                int addressId = networkAddressInventoryRegister.getOrCreate(networkAddress);
+                JsonObject mapping = new JsonObject();
+                mapping.addProperty(ADDRESS_ID, addressId);
+                mapping.addProperty(NETWORK_ADDRESS, networkAddress);
+                responseArray.add(mapping);
+            }
+        } catch (IOException e) {
+            logger.error(e.getMessage(), e);
+        }
+        return responseArray;
+    }
+}
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/ServiceNameDiscoveryServiceHandler.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/ServiceNameDiscoveryServiceHandler.java
new file mode 100644
index 000000000..248dc61c2
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/ServiceNameDiscoveryServiceHandler.java
@@ -0,0 +1,86 @@
+/*
+ * 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.rest;
+
+import com.google.gson.*;
+import java.io.IOException;
+import java.util.Objects;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.skywalking.apm.network.language.agent.SpanType;
+import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
+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.jetty.*;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class ServiceNameDiscoveryServiceHandler extends JettyJsonHandler {
+
+    private static final Logger logger = LoggerFactory.getLogger(ServiceNameDiscoveryServiceHandler.class);
+
+    private final IEndpointInventoryRegister inventoryService;
+    private final Gson gson = new Gson();
+
+    private static final String APPLICATION_ID = "ai";
+    private static final String SERVICE_NAME = "sn";
+    private static final String SRC_SPAN_TYPE = "st";
+    private static final String SERVICE_ID = "si";
+    private static final String ELEMENT = "el";
+
+    public ServiceNameDiscoveryServiceHandler(ModuleManager moduleManager) {
+        this.inventoryService = moduleManager.find(CoreModule.NAME).getService(IEndpointInventoryRegister.class);
+    }
+
+    @Override public String pathSpec() {
+        return "/servicename/discovery";
+    }
+
+    @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
+        JsonArray responseArray = new JsonArray();
+        try {
+            JsonArray services = gson.fromJson(req.getReader(), JsonArray.class);
+            for (JsonElement service : services) {
+                int applicationId = service.getAsJsonObject().get(APPLICATION_ID).getAsInt();
+                String serviceName = service.getAsJsonObject().get(SERVICE_NAME).getAsString();
+                int srcSpanType = service.getAsJsonObject().get(SRC_SPAN_TYPE).getAsInt();
+
+                SpanType spanType = SpanType.forNumber(srcSpanType);
+                if (Objects.nonNull(spanType)) {
+                    int serviceId = inventoryService.getOrCreate(applicationId, serviceName, DetectPoint.fromSpanType(spanType));
+                    if (serviceId != 0) {
+                        JsonObject responseJson = new JsonObject();
+                        responseJson.addProperty(SERVICE_ID, serviceId);
+                        responseJson.add(ELEMENT, service);
+                        responseArray.add(responseJson);
+                    }
+                }
+            }
+        } catch (IOException e) {
+            logger.error(e.getMessage(), e);
+        }
+        return responseArray;
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceModuleProvider.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceModuleProvider.java
index 83065eadc..c7ea0f1dc 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceModuleProvider.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceModuleProvider.java
@@ -20,10 +20,11 @@
 
 import java.io.IOException;
 import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
+import org.apache.skywalking.oap.server.core.server.*;
 import org.apache.skywalking.oap.server.library.module.*;
 import org.apache.skywalking.oap.server.receiver.trace.module.TraceModule;
-import org.apache.skywalking.oap.server.receiver.trace.provider.handler.TraceSegmentServiceHandler;
+import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.grpc.TraceSegmentServiceHandler;
+import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.rest.TraceSegmentServletHandler;
 import org.apache.skywalking.oap.server.receiver.trace.provider.parser.*;
 import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.endpoint.MultiScopesSpanListener;
 import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.segment.SegmentSpanListener;
@@ -64,9 +65,11 @@ public TraceModuleProvider() {
         listenerManager.add(new SegmentSpanListener.Factory());
 
         GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class);
+        JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).getService(JettyHandlerRegister.class);
         try {
             SegmentParse segmentParse = new SegmentParse(getManager(), listenerManager);
             grpcHandlerRegister.addHandler(new TraceSegmentServiceHandler(segmentParse));
+            jettyHandlerRegister.addHandler(new TraceSegmentServletHandler(segmentParse));
 
             SegmentStandardizationWorker standardizationWorker = new SegmentStandardizationWorker(segmentParse, moduleConfig.getBufferPath(), moduleConfig.getBufferOffsetMaxFileSize(), moduleConfig.getBufferDataMaxFileSize(), moduleConfig.isBufferFileCleanWhenRestart());
             segmentParse.setStandardizationWorker(standardizationWorker);
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/SegmentCounter.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/grpc/SegmentCounter.java
similarity index 98%
rename from oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/SegmentCounter.java
rename to oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/grpc/SegmentCounter.java
index 1c75d9d63..e65030afd 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/SegmentCounter.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/grpc/SegmentCounter.java
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.skywalking.oap.server.receiver.trace.provider.handler;
+package org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.grpc;
 
 import java.util.concurrent.atomic.AtomicLong;
 
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/TraceSegmentServiceHandler.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/grpc/TraceSegmentServiceHandler.java
similarity index 99%
rename from oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/TraceSegmentServiceHandler.java
rename to oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/grpc/TraceSegmentServiceHandler.java
index 908395af6..cbc2d1a6c 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/TraceSegmentServiceHandler.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/grpc/TraceSegmentServiceHandler.java
@@ -16,7 +16,7 @@
  *
  */
 
-package org.apache.skywalking.oap.server.receiver.trace.provider.handler;
+package org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.grpc;
 
 import io.grpc.stub.StreamObserver;
 import org.apache.skywalking.apm.network.language.agent.*;
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/TraceSegmentServletHandler.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/TraceSegmentServletHandler.java
new file mode 100644
index 000000000..0493c0cee
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/TraceSegmentServletHandler.java
@@ -0,0 +1,78 @@
+/*
+ * 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.trace.provider.handler.v5.rest;
+
+import com.google.gson.JsonElement;
+import com.google.gson.stream.JsonReader;
+import java.io.*;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.skywalking.oap.server.library.server.jetty.JettyJsonHandler;
+import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.rest.reader.*;
+import org.apache.skywalking.oap.server.receiver.trace.provider.parser.SegmentParse;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class TraceSegmentServletHandler extends JettyJsonHandler {
+
+    private static final Logger logger = LoggerFactory.getLogger(TraceSegmentServletHandler.class);
+
+    private final SegmentParse segmentParse;
+
+    public TraceSegmentServletHandler(SegmentParse segmentParse) {
+        this.segmentParse = segmentParse;
+    }
+
+    @Override public String pathSpec() {
+        return "/segments";
+    }
+
+    @Override protected JsonElement doGet(HttpServletRequest req) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override protected JsonElement doPost(HttpServletRequest req) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("receive stream segment");
+        }
+
+        try {
+            BufferedReader bufferedReader = req.getReader();
+            read(bufferedReader);
+        } catch (IOException e) {
+            logger.error(e.getMessage(), e);
+        }
+
+        return null;
+    }
+
+    private TraceSegmentJsonReader jsonReader = new TraceSegmentJsonReader();
+
+    private void read(BufferedReader bufferedReader) throws IOException {
+        JsonReader reader = new JsonReader(bufferedReader);
+
+        reader.beginArray();
+        while (reader.hasNext()) {
+            TraceSegment traceSegment = jsonReader.read(reader);
+            segmentParse.parse(traceSegment.getUpstreamSegment(), SegmentParse.Source.Agent);
+        }
+        reader.endArray();
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/KeyWithStringValueJsonReader.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/KeyWithStringValueJsonReader.java
new file mode 100644
index 000000000..95739b41f
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/KeyWithStringValueJsonReader.java
@@ -0,0 +1,54 @@
+/*
+ * 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.trace.provider.handler.v5.rest.reader;
+
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+import org.apache.skywalking.apm.network.language.agent.KeyWithStringValue;
+
+/**
+ * @author peng-yongsheng
+ */
+public class KeyWithStringValueJsonReader implements StreamJsonReader<KeyWithStringValue> {
+
+    private static final String KEY = "k";
+    private static final String VALUE = "v";
+
+    @Override public KeyWithStringValue read(JsonReader reader) throws IOException {
+        KeyWithStringValue.Builder builder = KeyWithStringValue.newBuilder();
+
+        reader.beginObject();
+        while (reader.hasNext()) {
+            switch (reader.nextName()) {
+                case KEY:
+                    builder.setKey(reader.nextString());
+                    break;
+                case VALUE:
+                    builder.setValue(reader.nextString());
+                    break;
+                default:
+                    reader.skipValue();
+                    break;
+            }
+        }
+        reader.endObject();
+
+        return builder.build();
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/LogJsonReader.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/LogJsonReader.java
new file mode 100644
index 000000000..ddacc91ec
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/LogJsonReader.java
@@ -0,0 +1,60 @@
+/*
+ * 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.trace.provider.handler.v5.rest.reader;
+
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+import org.apache.skywalking.apm.network.language.agent.LogMessage;
+
+/**
+ * @author peng-yongsheng
+ */
+public class LogJsonReader implements StreamJsonReader<LogMessage> {
+
+    private KeyWithStringValueJsonReader keyWithStringValueJsonReader = new KeyWithStringValueJsonReader();
+
+    private static final String TIME = "ti";
+    private static final String LOG_DATA = "ld";
+
+    @Override public LogMessage read(JsonReader reader) throws IOException {
+        LogMessage.Builder builder = LogMessage.newBuilder();
+
+        reader.beginObject();
+        while (reader.hasNext()) {
+            switch (reader.nextName()) {
+                case TIME:
+                    builder.setTime(reader.nextLong());
+                    break;
+                case LOG_DATA:
+                    reader.beginArray();
+                    while (reader.hasNext()) {
+                        builder.addData(keyWithStringValueJsonReader.read(reader));
+                    }
+                    reader.endArray();
+                    break;
+                default:
+                    reader.skipValue();
+                    break;
+            }
+        }
+        reader.endObject();
+
+        return builder.build();
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/ReferenceJsonReader.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/ReferenceJsonReader.java
new file mode 100644
index 000000000..65c6b7ad5
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/ReferenceJsonReader.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.receiver.trace.provider.handler.v5.rest.reader;
+
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+import org.apache.skywalking.apm.network.language.agent.TraceSegmentReference;
+
+/**
+ * @author peng-yongsheng
+ */
+public class ReferenceJsonReader implements StreamJsonReader<TraceSegmentReference> {
+
+    private UniqueIdJsonReader uniqueIdJsonReader = new UniqueIdJsonReader();
+
+    private static final String PARENT_TRACE_SEGMENT_ID = "pts";
+    private static final String PARENT_APPLICATION_INSTANCE_ID = "pii";
+    private static final String PARENT_SPAN_ID = "psp";
+    private static final String PARENT_SERVICE_ID = "psi";
+    private static final String PARENT_SERVICE_NAME = "psn";
+    private static final String NETWORK_ADDRESS_ID = "ni";
+    private static final String NETWORK_ADDRESS = "nn";
+    private static final String ENTRY_APPLICATION_INSTANCE_ID = "eii";
+    private static final String ENTRY_SERVICE_ID = "esi";
+    private static final String ENTRY_SERVICE_NAME = "esn";
+    private static final String REF_TYPE_VALUE = "rv";
+
+    @Override public TraceSegmentReference read(JsonReader reader) throws IOException {
+        TraceSegmentReference.Builder builder = TraceSegmentReference.newBuilder();
+
+        reader.beginObject();
+        while (reader.hasNext()) {
+            switch (reader.nextName()) {
+                case PARENT_TRACE_SEGMENT_ID:
+                    builder.setParentTraceSegmentId(uniqueIdJsonReader.read(reader));
+                    break;
+                case PARENT_APPLICATION_INSTANCE_ID:
+                    builder.setParentApplicationInstanceId(reader.nextInt());
+                    break;
+                case PARENT_SPAN_ID:
+                    builder.setParentSpanId(reader.nextInt());
+                    break;
+                case PARENT_SERVICE_ID:
+                    builder.setParentServiceId(reader.nextInt());
+                    break;
+                case PARENT_SERVICE_NAME:
+                    builder.setParentServiceName(reader.nextString());
+                    break;
+                case NETWORK_ADDRESS_ID:
+                    builder.setNetworkAddressId(reader.nextInt());
+                    break;
+                case NETWORK_ADDRESS:
+                    builder.setNetworkAddress(reader.nextString());
+                    break;
+                case ENTRY_APPLICATION_INSTANCE_ID:
+                    builder.setEntryApplicationInstanceId(reader.nextInt());
+                    break;
+                case ENTRY_SERVICE_ID:
+                    builder.setEntryServiceId(reader.nextInt());
+                    break;
+                case ENTRY_SERVICE_NAME:
+                    builder.setEntryServiceName(reader.nextString());
+                    break;
+                case REF_TYPE_VALUE:
+                    builder.setRefTypeValue(reader.nextInt());
+                    break;
+                default:
+                    reader.skipValue();
+                    break;
+            }
+        }
+        reader.endObject();
+
+        return builder.build();
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/SegmentJsonReader.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/SegmentJsonReader.java
new file mode 100644
index 000000000..eab2406be
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/SegmentJsonReader.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.receiver.trace.provider.handler.v5.rest.reader;
+
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+import org.apache.skywalking.apm.network.language.agent.TraceSegmentObject;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class SegmentJsonReader implements StreamJsonReader<TraceSegmentObject.Builder> {
+
+    private static final Logger logger = LoggerFactory.getLogger(SegmentJsonReader.class);
+
+    private UniqueIdJsonReader uniqueIdJsonReader = new UniqueIdJsonReader();
+    private SpanJsonReader spanJsonReader = new SpanJsonReader();
+
+    private static final String TRACE_SEGMENT_ID = "ts";
+    private static final String APPLICATION_ID = "ai";
+    private static final String APPLICATION_INSTANCE_ID = "ii";
+    private static final String SPANS = "ss";
+
+    @Override public TraceSegmentObject.Builder read(JsonReader reader) throws IOException {
+        TraceSegmentObject.Builder builder = TraceSegmentObject.newBuilder();
+
+        reader.beginObject();
+        while (reader.hasNext()) {
+            switch (reader.nextName()) {
+                case TRACE_SEGMENT_ID:
+                    builder.setTraceSegmentId(uniqueIdJsonReader.read(reader));
+                    if (logger.isDebugEnabled()) {
+                        StringBuilder segmentId = new StringBuilder();
+                        builder.getTraceSegmentId().getIdPartsList().forEach(idPart -> segmentId.append(idPart));
+                        logger.debug("segment id: {}", segmentId);
+                    }
+                    break;
+                case APPLICATION_ID:
+                    builder.setApplicationId(reader.nextInt());
+                    break;
+                case APPLICATION_INSTANCE_ID:
+                    builder.setApplicationInstanceId(reader.nextInt());
+                    break;
+                case SPANS:
+                    reader.beginArray();
+                    while (reader.hasNext()) {
+                        builder.addSpans(spanJsonReader.read(reader));
+                    }
+                    reader.endArray();
+                    break;
+                default:
+                    reader.skipValue();
+                    break;
+            }
+        }
+        reader.endObject();
+
+        return builder;
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/SpanJsonReader.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/SpanJsonReader.java
new file mode 100644
index 000000000..ef9471fda
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/SpanJsonReader.java
@@ -0,0 +1,126 @@
+/*
+ * 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.trace.provider.handler.v5.rest.reader;
+
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+import org.apache.skywalking.apm.network.language.agent.SpanObject;
+
+/**
+ * @author peng-yongsheng
+ */
+public class SpanJsonReader implements StreamJsonReader<SpanObject> {
+
+    private KeyWithStringValueJsonReader keyWithStringValueJsonReader = new KeyWithStringValueJsonReader();
+    private LogJsonReader logJsonReader = new LogJsonReader();
+    private ReferenceJsonReader referenceJsonReader = new ReferenceJsonReader();
+
+    private static final String SPAN_ID = "si";
+    private static final String SPAN_TYPE_VALUE = "tv";
+    private static final String SPAN_LAYER_VALUE = "lv";
+    private static final String PARENT_SPAN_ID = "ps";
+    private static final String START_TIME = "st";
+    private static final String END_TIME = "et";
+    private static final String COMPONENT_ID = "ci";
+    private static final String COMPONENT_NAME = "cn";
+    private static final String OPERATION_NAME_ID = "oi";
+    private static final String OPERATION_NAME = "on";
+    private static final String PEER_ID = "pi";
+    private static final String PEER = "pn";
+    private static final String IS_ERROR = "ie";
+    private static final String TRACE_SEGMENT_REFERENCE = "rs";
+    private static final String TAGS = "to";
+    private static final String LOGS = "lo";
+
+    @Override public SpanObject read(JsonReader reader) throws IOException {
+        SpanObject.Builder builder = SpanObject.newBuilder();
+
+        reader.beginObject();
+        while (reader.hasNext()) {
+            switch (reader.nextName()) {
+                case SPAN_ID:
+                    builder.setSpanId(reader.nextInt());
+                    break;
+                case SPAN_TYPE_VALUE:
+                    builder.setSpanTypeValue(reader.nextInt());
+                    break;
+                case SPAN_LAYER_VALUE:
+                    builder.setSpanLayerValue(reader.nextInt());
+                    break;
+                case PARENT_SPAN_ID:
+                    builder.setParentSpanId(reader.nextInt());
+                    break;
+                case START_TIME:
+                    builder.setStartTime(reader.nextLong());
+                    break;
+                case END_TIME:
+                    builder.setEndTime(reader.nextLong());
+                    break;
+                case COMPONENT_ID:
+                    builder.setComponentId(reader.nextInt());
+                    break;
+                case COMPONENT_NAME:
+                    builder.setComponent(reader.nextString());
+                    break;
+                case OPERATION_NAME_ID:
+                    builder.setOperationNameId(reader.nextInt());
+                    break;
+                case OPERATION_NAME:
+                    builder.setOperationName(reader.nextString());
+                    break;
+                case PEER_ID:
+                    builder.setPeerId(reader.nextInt());
+                    break;
+                case PEER:
+                    builder.setPeer(reader.nextString());
+                    break;
+                case IS_ERROR:
+                    builder.setIsError(reader.nextBoolean());
+                    break;
+                case TRACE_SEGMENT_REFERENCE:
+                    reader.beginArray();
+                    while (reader.hasNext()) {
+                        builder.addRefs(referenceJsonReader.read(reader));
+                    }
+                    reader.endArray();
+                    break;
+                case TAGS:
+                    reader.beginArray();
+                    while (reader.hasNext()) {
+                        builder.addTags(keyWithStringValueJsonReader.read(reader));
+                    }
+                    reader.endArray();
+                    break;
+                case LOGS:
+                    reader.beginArray();
+                    while (reader.hasNext()) {
+                        builder.addLogs(logJsonReader.read(reader));
+                    }
+                    reader.endArray();
+                    break;
+                default:
+                    reader.skipValue();
+                    break;
+            }
+        }
+        reader.endObject();
+
+        return builder.build();
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/StreamJsonReader.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/StreamJsonReader.java
new file mode 100644
index 000000000..cc144c6d6
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/StreamJsonReader.java
@@ -0,0 +1,29 @@
+/*
+ * 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.trace.provider.handler.v5.rest.reader;
+
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+
+/**
+ * @author peng-yongsheng
+ */
+public interface StreamJsonReader<T> {
+    T read(JsonReader reader) throws IOException;
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/TraceSegment.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/TraceSegment.java
new file mode 100644
index 000000000..4ca230b10
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/TraceSegment.java
@@ -0,0 +1,45 @@
+/*
+ * 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.trace.provider.handler.v5.rest.reader;
+
+import org.apache.skywalking.apm.network.language.agent.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class TraceSegment {
+
+    private UpstreamSegment.Builder builder;
+
+    public TraceSegment() {
+        builder = UpstreamSegment.newBuilder();
+    }
+
+    public void addGlobalTraceId(UniqueId.Builder globalTraceId) {
+        builder.addGlobalTraceIds(globalTraceId);
+    }
+
+    public void setTraceSegmentBuilder(TraceSegmentObject.Builder traceSegmentBuilder) {
+        builder.setSegment(traceSegmentBuilder.build().toByteString());
+    }
+
+    public UpstreamSegment getUpstreamSegment() {
+        return builder.build();
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/TraceSegmentJsonReader.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/TraceSegmentJsonReader.java
new file mode 100644
index 000000000..26e2358a4
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/TraceSegmentJsonReader.java
@@ -0,0 +1,64 @@
+/*
+ * 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.trace.provider.handler.v5.rest.reader;
+
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+import org.slf4j.*;
+
+/**
+ * @author peng-yongsheng
+ */
+public class TraceSegmentJsonReader implements StreamJsonReader<TraceSegment> {
+
+    private static final Logger logger = LoggerFactory.getLogger(TraceSegmentJsonReader.class);
+
+    private UniqueIdJsonReader uniqueIdJsonReader = new UniqueIdJsonReader();
+    private SegmentJsonReader segmentJsonReader = new SegmentJsonReader();
+
+    private static final String GLOBAL_TRACE_IDS = "gt";
+    private static final String SEGMENT = "sg";
+
+    @Override public TraceSegment read(JsonReader reader) throws IOException {
+        TraceSegment traceSegment = new TraceSegment();
+
+        reader.beginObject();
+        while (reader.hasNext()) {
+            switch (reader.nextName()) {
+                case GLOBAL_TRACE_IDS:
+                    reader.beginArray();
+                    while (reader.hasNext()) {
+                        traceSegment.addGlobalTraceId(uniqueIdJsonReader.read(reader));
+                    }
+                    reader.endArray();
+
+                    break;
+                case SEGMENT:
+                    traceSegment.setTraceSegmentBuilder(segmentJsonReader.read(reader));
+                    break;
+                default:
+                    reader.skipValue();
+                    break;
+            }
+        }
+        reader.endObject();
+
+        return traceSegment;
+    }
+}
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/UniqueIdJsonReader.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/UniqueIdJsonReader.java
new file mode 100644
index 000000000..43465eba0
--- /dev/null
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/handler/v5/rest/reader/UniqueIdJsonReader.java
@@ -0,0 +1,40 @@
+/*
+ * 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.trace.provider.handler.v5.rest.reader;
+
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+import org.apache.skywalking.apm.network.language.agent.UniqueId;
+
+/**
+ * @author peng-yongsheng
+ */
+public class UniqueIdJsonReader implements StreamJsonReader<UniqueId.Builder> {
+
+    @Override public UniqueId.Builder read(JsonReader reader) throws IOException {
+        UniqueId.Builder builder = UniqueId.newBuilder();
+
+        reader.beginArray();
+        while (reader.hasNext()) {
+            builder.addIdParts(reader.nextLong());
+        }
+        reader.endArray();
+        return builder;
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services