You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/09/12 01:41:18 UTC
[incubator-servicecomb-java-chassis] 02/13: [SCB-881] add
invocation.isEdge()
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 7810a8b7923c6449b4896b887e209b55c9128595
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Sep 7 08:56:12 2018 +0800
[SCB-881] add invocation.isEdge()
---
.../main/java/org/apache/servicecomb/core/Invocation.java | 12 ++++++++++++
.../src/main/java/org/apache/servicecomb/core/SCBEngine.java | 8 ++++----
.../test/java/org/apache/servicecomb/core/TestSCBEngine.java | 2 +-
.../org/apache/servicecomb/edge/core/EdgeInvocation.java | 1 +
.../org/apache/servicecomb/edge/core/TestEdgeInvocation.java | 1 +
5 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/core/src/main/java/org/apache/servicecomb/core/Invocation.java b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
index 43dc36b..617673f 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
@@ -76,6 +76,10 @@ public class Invocation extends SwaggerInvocation {
private HttpServletRequestEx requestEx;
+ // not extend InvocationType
+ // because isEdge() only affect to apm/metrics output, no need to change so many logic
+ private boolean edge;
+
public HttpServletRequestEx getRequestEx() {
return requestEx;
}
@@ -275,4 +279,12 @@ public class Invocation extends SwaggerInvocation {
public boolean isConsumer() {
return InvocationType.CONSUMER.equals(invocationType);
}
+
+ public boolean isEdge() {
+ return edge;
+ }
+
+ public void setEdge(boolean edge) {
+ this.edge = edge;
+ }
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
index 15b4ee9..4be7e7c 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
@@ -80,6 +80,10 @@ public class SCBEngine {
private volatile SCBStatus status = SCBStatus.DOWN;
+ private EventBus eventBus = EventManager.getEventBus();
+
+ private static final SCBEngine INSTANCE = new SCBEngine();
+
public void setStatus(SCBStatus status) {
this.status = status;
}
@@ -88,10 +92,6 @@ public class SCBEngine {
return status;
}
- private EventBus eventBus = EventManager.getEventBus();
-
- private static final SCBEngine INSTANCE = new SCBEngine();
-
public static SCBEngine getInstance() {
return INSTANCE;
}
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java b/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java
index 6c1e605..7ad7ce4 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java
@@ -168,7 +168,7 @@ public class TestSCBEngine {
SCBEngine engine = new SCBEngine();
engine.setBootListenerList(Arrays.asList(event -> eventEngine.value = event.getScbEngine()));
engine.triggerEvent(EventType.AFTER_REGISTRY);
-
+
Assert.assertNotNull(eventEngine.value);
}
}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeInvocation.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeInvocation.java
index 742762a..fb885a5 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeInvocation.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeInvocation.java
@@ -127,6 +127,7 @@ public class EdgeInvocation extends AbstractRestInvocation {
restOperationMeta.getOperationMeta(),
null);
this.invocation.setSync(false);
+ this.invocation.setEdge(true);
this.invocation.getHandlerContext().put(EDGE_INVOCATION_CONTEXT, Vertx.currentContext());
this.invocation.setResponseExecutor(new ReactiveResponseExecutor());
this.routingContext.put(RestConst.REST_INVOCATION_CONTEXT, invocation);
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestEdgeInvocation.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestEdgeInvocation.java
index 67a59d2..538e979 100644
--- a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestEdgeInvocation.java
+++ b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestEdgeInvocation.java
@@ -235,6 +235,7 @@ public class TestEdgeInvocation {
Invocation invocation = Deencapsulation.getField(edgeInvocation, "invocation");
Assert.assertThat(invocation.getResponseExecutor(), Matchers.instanceOf(ReactiveResponseExecutor.class));
Assert.assertFalse(invocation.isSync());
+ Assert.assertTrue(invocation.isEdge());
Assert.assertSame(context, invocation.getHandlerContext().get(EdgeInvocation.EDGE_INVOCATION_CONTEXT));
}