-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#80][Part-3] feat: add REST API for decommisson #684
Merged
Merged
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
21f1e17
Temporary submission
xianjingfeng cdf91fc
Merge branch 'master' into issue_80_2
xianjingfeng 6ef0ba6
Temporary submission
xianjingfeng 5663623
Temporary submission
xianjingfeng 6b62ffc
Merge branch 'master' into issue_80_2
xianjingfeng 8559119
Complete the rpc section
xianjingfeng 6d433ae
Optimize
xianjingfeng 376320f
Merge branch 'master' into issue_80_2
xianjingfeng 5e33f33
Fix code style.
xianjingfeng 4d1f539
Optimize
xianjingfeng ffa3456
Optimize
xianjingfeng 7b37fa7
Optimize
xianjingfeng 8840a61
Merge branch 'issue_80_2' into issue_80_part3
xianjingfeng ea37b61
Fix UT
xianjingfeng bc5f988
test
xianjingfeng d4a3fc6
test
xianjingfeng c4a5e2a
Revert "test"
xianjingfeng 5f6b66b
Revert "test"
xianjingfeng 840b740
test
xianjingfeng c8e5ae0
testOptimize
xianjingfeng d61b6ce
Fix license
xianjingfeng 2381092
Optimize
xianjingfeng c64aaa7
Add docs
xianjingfeng f0e1ef5
Add docsOptimize
xianjingfeng fddc053
Optimize
xianjingfeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
71 changes: 71 additions & 0 deletions
71
coordinator/src/main/java/org/apache/uniffle/coordinator/web/Response.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,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.uniffle.coordinator.web; | ||
|
||
public class Response<T> { | ||
private static final int SUCCESS_CODE = 0; | ||
private static final int ERROR_CODE = -1; | ||
private int code; | ||
private T data; | ||
private String errMsg; | ||
|
||
public Response() { | ||
} | ||
|
||
public Response(int code, T data, String errMsg) { | ||
this.code = code; | ||
this.data = data; | ||
this.errMsg = errMsg; | ||
} | ||
|
||
public static <T> Response<T> success(T data) { | ||
return new Response<>(SUCCESS_CODE, data, null); | ||
} | ||
|
||
public static <T> Response<T> fail(String msg) { | ||
return new Response<>(ERROR_CODE, null, msg); | ||
} | ||
|
||
public static <T> Response<T> fail(String msg, int code) { | ||
return new Response<>(code, null, msg); | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(int code) { | ||
this.code = code; | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
|
||
public void setData(T data) { | ||
this.data = data; | ||
} | ||
|
||
public String getErrMsg() { | ||
return errMsg; | ||
} | ||
|
||
public void setErrMsg(String errMsg) { | ||
this.errMsg = errMsg; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...r/src/main/java/org/apache/uniffle/coordinator/web/request/CancelDecommissionRequest.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,32 @@ | ||
/* | ||
* 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.uniffle.coordinator.web.request; | ||
|
||
import java.util.List; | ||
|
||
public class CancelDecommissionRequest { | ||
private List<String> serverIds; | ||
|
||
public List<String> getServerIds() { | ||
return serverIds; | ||
} | ||
|
||
public void setServerIds(List<String> serverIds) { | ||
this.serverIds = serverIds; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...dinator/src/main/java/org/apache/uniffle/coordinator/web/request/DecommissionRequest.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,33 @@ | ||
/* | ||
* 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.uniffle.coordinator.web.request; | ||
|
||
import java.util.List; | ||
|
||
public class DecommissionRequest { | ||
private List<String> serverIds; | ||
xianjingfeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public List<String> getServerIds() { | ||
return serverIds; | ||
} | ||
|
||
public void setServerIds(List<String> serverIds) { | ||
this.serverIds = serverIds; | ||
} | ||
|
||
xianjingfeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
85 changes: 85 additions & 0 deletions
85
coordinator/src/main/java/org/apache/uniffle/coordinator/web/servlet/BaseServlet.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,85 @@ | ||
/* | ||
* 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.uniffle.coordinator.web.servlet; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.concurrent.Callable; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import org.apache.uniffle.coordinator.web.Response; | ||
|
||
public abstract class BaseServlet extends HttpServlet { | ||
public static final String JSON_MIME_TYPE = "application/json"; | ||
final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
writeJSON(resp, handlerRequest(() -> handleGet(req, resp))); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
writeJSON(resp, handlerRequest(() -> handlePost(req, resp))); | ||
} | ||
|
||
private Response handlerRequest( | ||
Callable<Response> function) { | ||
Response response; | ||
try { | ||
// todo: Do something for authentication | ||
response = function.call(); | ||
} catch (Exception e) { | ||
response = Response.fail(e.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
protected Response handleGet( | ||
HttpServletRequest req, | ||
HttpServletResponse resp) throws ServletException, IOException { | ||
throw new IOException("Method not support!"); | ||
} | ||
|
||
|
||
xianjingfeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
protected Response handlePost( | ||
HttpServletRequest req, | ||
HttpServletResponse resp) throws ServletException, IOException { | ||
throw new IOException("Method not support!"); | ||
} | ||
|
||
protected void writeJSON(final HttpServletResponse resp, final Object obj) | ||
throws IOException { | ||
if (obj == null) { | ||
return; | ||
} | ||
resp.setContentType(JSON_MIME_TYPE); | ||
final OutputStream stream = resp.getOutputStream(); | ||
mapper.writeValue(stream, obj); | ||
} | ||
|
||
protected <T> T parseParamsFromJson(HttpServletRequest req, Class<T> clazz) throws IOException { | ||
advancedxy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return mapper.readValue(req.getInputStream(), clazz); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...r/src/main/java/org/apache/uniffle/coordinator/web/servlet/CancelDecommissionServlet.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,50 @@ | ||
/* | ||
* 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.uniffle.coordinator.web.servlet; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.commons.collections.CollectionUtils; | ||
|
||
import org.apache.uniffle.coordinator.ClusterManager; | ||
import org.apache.uniffle.coordinator.CoordinatorServer; | ||
import org.apache.uniffle.coordinator.web.Response; | ||
import org.apache.uniffle.coordinator.web.request.CancelDecommissionRequest; | ||
|
||
public class CancelDecommissionServlet extends BaseServlet { | ||
private final CoordinatorServer coordinator; | ||
|
||
public CancelDecommissionServlet(CoordinatorServer coordinator) { | ||
this.coordinator = coordinator; | ||
} | ||
|
||
@Override | ||
protected Response handlePost(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
CancelDecommissionRequest params = parseParamsFromJson(req, CancelDecommissionRequest.class); | ||
if (CollectionUtils.isEmpty(params.getServerIds())) { | ||
return Response.fail("Parameter[serverIds] should not be null!"); | ||
} | ||
ClusterManager clusterManager = coordinator.getClusterManager(); | ||
params.getServerIds().forEach((serverId) -> { | ||
clusterManager.cancelDecommission(serverId); | ||
}); | ||
return Response.success(null); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you think to struct REST api as follows:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is troublesome to get parameters from path in the current framework. Should we introduce other REST frameworks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's too much trouble, I'm OK with current route path. If it's simple, I prefer the above REST path, which is more idiomatic. It's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be more and more rest apis in the future. It is still troublesome to add an api under the current framework. So I think we can consider it later. How about introduce Jersey? @advancedxy @jerqi @zuston @kaijchen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with Jersey. Is it lightweight enough? Is it used widely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Hadoop and Spark use Jersey either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if
Jersey
is lightweight. I hope the restful framework could be modern and lightweight.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with current status. Let's make the new REST server framework a followup PR. Jersey itself seems a bit complex, but the path annotation https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/user-guide.html#d0e2081 is quite elegant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can refer to Apache Livy, it use
scalatra
. We can use similar Java framework.https://www.51cto.com/article/311366.html