You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/12/04 07:55:07 UTC

[GitHub] [incubator-shardingsphere] ssxlulu commented on a change in pull request #3656: #3256 Provider Scaling out Interface-Initialize netty related classes

ssxlulu commented on a change in pull request #3656: #3256 Provider Scaling out Interface-Initialize netty related classes
URL: https://github.com/apache/incubator-shardingsphere/pull/3656#discussion_r353591435
 
 

 ##########
 File path: sharding-scaling/sharding-scaling-core/src/main/java/org/apache/shardingsphere/shardingscaling/core/web/HttpServerHandler.java
 ##########
 @@ -0,0 +1,124 @@
+/*
+ * 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.shardingsphere.shardingscaling.core.web;
+
+import com.google.gson.Gson;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.codec.http.DefaultFullHttpResponse;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.FullHttpResponse;
+import io.netty.handler.codec.http.HttpHeaderNames;
+import io.netty.handler.codec.http.HttpHeaderValues;
+import io.netty.handler.codec.http.HttpMethod;
+import io.netty.handler.codec.http.HttpRequest;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http.HttpUtil;
+import io.netty.util.CharsetUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.shardingscaling.core.controller.ScalingJobController;
+
+import java.util.regex.Pattern;
+
+
+/**
+ * Http server handler.
+ *
+ * @author ssxlulu
+ */
+@Slf4j
+public final class HttpServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
+
+    private static final Pattern URL_PATTERN = Pattern.compile("(^/shardingscaling/start)|(^/shardingscaling/(progress|stop)/\\d+)",
+            Pattern.CASE_INSENSITIVE);
+
+    private static final Gson GSON = new Gson();
+
+    private static final ScalingJobController SCALING_JOB_CONTROLLER = new ScalingJobController();
+
+    @Override
+    protected void channelRead0(final ChannelHandlerContext channelHandlerContext, final FullHttpRequest request) {
+        String requestPath = request.uri();
+        String requestBody = request.content().toString(CharsetUtil.UTF_8);
+        HttpMethod method = request.method();
+        if (!URL_PATTERN.matcher(requestPath).matches()) {
+            response("not support request", channelHandlerContext, HttpResponseStatus.BAD_REQUEST, request);
+            return;
+        }
+        if ("/shardingscaling/start".equalsIgnoreCase(requestPath) && method.equals(HttpMethod.POST)) {
+            startShardingScalingJob(requestBody);
+            response("start", channelHandlerContext, HttpResponseStatus.OK, request);
+            return;
+        }
+        if (requestPath.contains("/shardingscaling/progress/") && method.equals(HttpMethod.GET)) {
+            //TODO
+            response("progress", channelHandlerContext, HttpResponseStatus.OK, request);
+            return;
+        }
+        if (requestPath.contains("/shardingscaling/stop/") && method.equals(HttpMethod.DELETE)) {
 
 Review comment:
   Yes, the APIS should be changed, here are the final discussion result:
   ```
   post:
   job/start/
   job/stop/
   
   get:
   job/progress/${id}
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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