forked from apache/eventmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
314 additions
and
171 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
eventmesh-admin-server/src/main/java/com/apache/eventmesh/admin/server/Admin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
eventmesh-admin-server/src/main/java/com/apache/eventmesh/admin/server/AdminServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 31 additions & 14 deletions
45
...esh-admin-server/src/main/java/com/apache/eventmesh/admin/server/web/AdminGrpcServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,65 @@ | ||
package com.apache.eventmesh.admin.server.web; | ||
|
||
import com.apache.eventmesh.admin.server.web.handler.BaseRequestHandler; | ||
import com.apache.eventmesh.admin.server.web.handler.RequestHandlerFactory; | ||
import com.google.protobuf.Any; | ||
import com.google.protobuf.UnsafeByteOperations; | ||
import io.grpc.stub.ServerCallStreamObserver; | ||
import io.grpc.stub.StreamObserver; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.eventmesh.common.adminserver.response.BaseResponse; | ||
import org.apache.eventmesh.common.adminserver.response.FailResponse; | ||
import org.apache.eventmesh.common.remote.payload.PayloadUtil; | ||
import org.apache.eventmesh.common.remote.request.BaseGrpcRequest; | ||
import org.apache.eventmesh.common.remote.response.BaseGrpcResponse; | ||
import org.apache.eventmesh.common.remote.response.FailResponse; | ||
import org.apache.eventmesh.common.protocol.grpc.adminserver.AdminServiceGrpc; | ||
import org.apache.eventmesh.common.protocol.grpc.adminserver.Payload; | ||
import org.apache.eventmesh.common.utils.JsonUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
public class AdminGrpcServer extends AdminServiceGrpc.AdminServiceImplBase { | ||
@Autowired | ||
RequestHandlerFactory handlerFactory; | ||
|
||
private Payload process(Payload value) { | ||
if (value == null || StringUtils.isBlank(value.getMetadata().getType())) { | ||
|
||
return PayloadUtil.from(FailResponse.build(BaseGrpcResponse.UNKNOWN, "bad request")); | ||
} | ||
BaseRequestHandler<BaseGrpcRequest, BaseGrpcResponse> handler = | ||
handlerFactory.getHandler(value.getMetadata().getType()); | ||
if (handler == null) { | ||
return PayloadUtil.from(FailResponse.build(BaseGrpcResponse.UNKNOWN, | ||
"not match any request handler")); | ||
} | ||
return PayloadUtil.from(handler.handlerRequest(PayloadUtil.parse(value), value.getMetadata())); | ||
} | ||
|
||
public StreamObserver<Payload> invokeBiStream(StreamObserver<Payload> responseObserver) { | ||
return new StreamObserver<Payload>() { | ||
@Override | ||
public void onNext(Payload value) { | ||
if (value == null || StringUtils.isBlank(value.getMetadata().getType())) { | ||
responseObserver.onNext(Payload.newBuilder().setBody(Any.newBuilder().setValue(UnsafeByteOperations.unsafeWrap(JsonUtils.toJSONBytes(FailResponse.build(BaseResponse.UNKNOWN, "bad " + | ||
"request"))))).build()); | ||
return; | ||
} | ||
handlerFactory.getHandler(value.getMetadata().getType()); | ||
responseObserver.onNext(); | ||
responseObserver.onNext(process(value)); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
|
||
if (responseObserver instanceof ServerCallStreamObserver) { | ||
if (!((ServerCallStreamObserver<Payload>) responseObserver).isCancelled()) { | ||
log.warn("admin gRPC server fail", t); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onCompleted() { | ||
|
||
responseObserver.onCompleted(); | ||
} | ||
}; | ||
} | ||
|
||
public void invoke(Payload request, StreamObserver<Payload> responseObserver) { | ||
responseObserver.onNext(process(request)); | ||
responseObserver.onCompleted(); | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
...r/src/main/java/com/apache/eventmesh/admin/server/web/handler/AbstractRequestHandler.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...erver/src/main/java/com/apache/eventmesh/admin/server/web/handler/BaseRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.apache.eventmesh.admin.server.web.handler; | ||
|
||
import org.apache.eventmesh.common.remote.request.BaseGrpcRequest; | ||
import org.apache.eventmesh.common.remote.response.BaseGrpcResponse; | ||
import org.apache.eventmesh.common.protocol.grpc.adminserver.Metadata; | ||
|
||
public abstract class BaseRequestHandler<T extends BaseGrpcRequest, S extends BaseGrpcResponse> { | ||
public BaseGrpcResponse handlerRequest(T request, Metadata metadata) { | ||
return handler(request, metadata); | ||
} | ||
|
||
protected abstract S handler(T request, Metadata metadata); | ||
} |
6 changes: 3 additions & 3 deletions
6
...r/src/main/java/com/apache/eventmesh/admin/server/web/handler/FetchJobRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
eventmesh-common/src/main/java/org/apache/eventmesh/common/adminserver/IPayload.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
eventmesh-common/src/main/java/org/apache/eventmesh/common/adminserver/PayloadUtil.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
eventmesh-common/src/main/java/org/apache/eventmesh/common/adminserver/Position.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...esh-common/src/main/java/org/apache/eventmesh/common/adminserver/request/BaseRequest.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
...common/src/main/java/org/apache/eventmesh/common/adminserver/request/FetchJobRequest.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
.../src/main/java/org/apache/eventmesh/common/adminserver/request/ReportPositionRequest.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...h-common/src/main/java/org/apache/eventmesh/common/adminserver/response/BaseResponse.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...entmesh/common/adminserver/HeartBeat.java → ...he/eventmesh/common/remote/HeartBeat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...che/eventmesh/common/adminserver/Job.java → ...g/apache/eventmesh/common/remote/Job.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ventmesh/common/adminserver/JobState.java → ...che/eventmesh/common/remote/JobState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...eventmesh/common/adminserver/JobType.java → ...ache/eventmesh/common/remote/JobType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
eventmesh-common/src/main/java/org/apache/eventmesh/common/remote/Position.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.apache.eventmesh.common.remote; | ||
|
||
public class Position { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...he/eventmesh/common/adminserver/Task.java → .../apache/eventmesh/common/remote/Task.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
eventmesh-common/src/main/java/org/apache/eventmesh/common/remote/exception/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.apache.eventmesh.common.remote.exception; | ||
|
||
public class ErrorCode { | ||
public static final int TYPE_IN_METADATA_NOT_EXISTS = 4001; | ||
} |
7 changes: 7 additions & 0 deletions
7
...on/src/main/java/org/apache/eventmesh/common/remote/exception/PayloadFormatException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.apache.eventmesh.common.remote.exception; | ||
|
||
public class PayloadFormatException extends RemoteRuntimeException { | ||
public PayloadFormatException(int code, String desc) { | ||
super(code, desc); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...on/src/main/java/org/apache/eventmesh/common/remote/exception/RemoteRuntimeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.apache.eventmesh.common.remote.exception; | ||
|
||
public class RemoteRuntimeException extends RuntimeException{ | ||
protected final int code; | ||
protected final String message; | ||
public RemoteRuntimeException(int code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...n/adminserver/job/DataSourceClassify.java → ...common/remote/job/DataSourceClassify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...adminserver/job/DataSourceDriverType.java → ...mmon/remote/job/DataSourceDriverType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ommon/adminserver/job/DataSourceType.java → ...esh/common/remote/job/DataSourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mon/adminserver/job/JobTransportType.java → ...h/common/remote/job/JobTransportType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
eventmesh-common/src/main/java/org/apache/eventmesh/common/remote/payload/IPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.apache.eventmesh.common.remote.payload; | ||
|
||
public interface IPayload { | ||
} |
Oops, something went wrong.