mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: Unified API management using ProtocolConstant #209
This commit is contained in:
parent
eda39a6372
commit
a575b65320
@ -8,11 +8,11 @@ package com.github.kfcfans.powerjob.common;
|
|||||||
*/
|
*/
|
||||||
public class ProtocolConstant {
|
public class ProtocolConstant {
|
||||||
|
|
||||||
public static final String SERVER_PATH_HEARTBEAT = "heartbeat";
|
public static final String SERVER_PATH_HEARTBEAT = "/server/heartbeat";
|
||||||
public static final String SERVER_PATH_STATUS_REPORT = "statusReport";
|
public static final String SERVER_PATH_STATUS_REPORT = "/server/statusReport";
|
||||||
public static final String SERVER_PATH_LOG_REPORT = "logReport";
|
public static final String SERVER_PATH_LOG_REPORT = "/server/logReport";
|
||||||
|
|
||||||
public static final String WORKER_PATH_DISPATCH_JOB = "/worker/dispatchJob";
|
public static final String WORKER_PATH_DISPATCH_JOB = "/worker/runJob";
|
||||||
public static final String WORKER_PATH_STOP_INSTANCE = "/worker/stopInstance";
|
public static final String WORKER_PATH_STOP_INSTANCE = "/worker/stopInstance";
|
||||||
public static final String WORKER_PATH_QUERY_INSTANCE_INFO = "/worker/queryInstanceInfo";
|
public static final String WORKER_PATH_QUERY_INSTANCE_INFO = "/worker/queryInstanceInfo";
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.kfcfans.powerjob.server.handler.outer;
|
package com.github.kfcfans.powerjob.server.handler.outer;
|
||||||
|
|
||||||
import com.github.kfcfans.powerjob.common.OmsConstant;
|
import com.github.kfcfans.powerjob.common.OmsConstant;
|
||||||
|
import com.github.kfcfans.powerjob.common.ProtocolConstant;
|
||||||
import com.github.kfcfans.powerjob.common.request.TaskTrackerReportInstanceStatusReq;
|
import com.github.kfcfans.powerjob.common.request.TaskTrackerReportInstanceStatusReq;
|
||||||
import com.github.kfcfans.powerjob.common.request.WorkerHeartbeat;
|
import com.github.kfcfans.powerjob.common.request.WorkerHeartbeat;
|
||||||
import com.github.kfcfans.powerjob.common.request.WorkerLogReportReq;
|
import com.github.kfcfans.powerjob.common.request.WorkerLogReportReq;
|
||||||
@ -15,7 +16,6 @@ import io.vertx.ext.web.Router;
|
|||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
import io.vertx.ext.web.handler.BodyHandler;
|
import io.vertx.ext.web.handler.BodyHandler;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static com.github.kfcfans.powerjob.server.handler.outer.WorkerRequestHandler.getWorkerRequestHandler;
|
import static com.github.kfcfans.powerjob.server.handler.outer.WorkerRequestHandler.getWorkerRequestHandler;
|
||||||
@ -28,8 +28,6 @@ import static com.github.kfcfans.powerjob.server.handler.outer.WorkerRequestHand
|
|||||||
*/
|
*/
|
||||||
public class WorkerRequestHttpHandler extends AbstractVerticle {
|
public class WorkerRequestHttpHandler extends AbstractVerticle {
|
||||||
|
|
||||||
private static final String HTTP_PREFIX = "/wrh/v1/";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
|
|
||||||
@ -41,18 +39,18 @@ public class WorkerRequestHttpHandler extends AbstractVerticle {
|
|||||||
|
|
||||||
Router router = Router.router(vertx);
|
Router router = Router.router(vertx);
|
||||||
router.route().handler(BodyHandler.create());
|
router.route().handler(BodyHandler.create());
|
||||||
router.post(HTTP_PREFIX + "heartbeat")
|
router.post(ProtocolConstant.SERVER_PATH_HEARTBEAT)
|
||||||
.handler(ctx -> {
|
.handler(ctx -> {
|
||||||
WorkerHeartbeat heartbeat = ctx.getBodyAsJson().mapTo(WorkerHeartbeat.class);
|
WorkerHeartbeat heartbeat = ctx.getBodyAsJson().mapTo(WorkerHeartbeat.class);
|
||||||
getWorkerRequestHandler().onReceiveWorkerHeartbeat(heartbeat);
|
getWorkerRequestHandler().onReceiveWorkerHeartbeat(heartbeat);
|
||||||
});
|
});
|
||||||
router.post(HTTP_PREFIX + "instanceStatusReport")
|
router.post(ProtocolConstant.SERVER_PATH_STATUS_REPORT)
|
||||||
.blockingHandler(ctx -> {
|
.blockingHandler(ctx -> {
|
||||||
TaskTrackerReportInstanceStatusReq req = ctx.getBodyAsJson().mapTo(TaskTrackerReportInstanceStatusReq.class);
|
TaskTrackerReportInstanceStatusReq req = ctx.getBodyAsJson().mapTo(TaskTrackerReportInstanceStatusReq.class);
|
||||||
Optional<AskResponse> askResponseOpt = getWorkerRequestHandler().onReceiveTaskTrackerReportInstanceStatusReq(req);
|
getWorkerRequestHandler().onReceiveTaskTrackerReportInstanceStatusReq(req);
|
||||||
askResponseOpt.ifPresent(askResponse -> out(ctx, askResponse));
|
out(ctx, AskResponse.succeed(null));
|
||||||
});
|
});
|
||||||
router.post(HTTP_PREFIX + "logReport")
|
router.post(ProtocolConstant.SERVER_PATH_LOG_REPORT)
|
||||||
.blockingHandler(ctx -> {
|
.blockingHandler(ctx -> {
|
||||||
WorkerLogReportReq req = ctx.getBodyAsJson().mapTo(WorkerLogReportReq.class);
|
WorkerLogReportReq req = ctx.getBodyAsJson().mapTo(WorkerLogReportReq.class);
|
||||||
getWorkerRequestHandler().onReceiveWorkerLogReportReq(req);
|
getWorkerRequestHandler().onReceiveWorkerLogReportReq(req);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user