-
Notifications
You must be signed in to change notification settings - Fork 63
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
PHOENIX-6074 Let PQS Act As An Admin Tool Rest Endpoint #48
Open
m2je
wants to merge
1
commit into
apache:master
Choose a base branch
from
m2je:PHOENIX-6074
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions
25
...x-queryserver/src/main/java/org/apache/phoenix/queryserver/server/admin/AdminCommand.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,25 @@ | ||
/* | ||
* 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.phoenix.queryserver.server.admin; | ||
|
||
/** | ||
* | ||
*/ | ||
public enum AdminCommand { | ||
IndexTool, IndexScrutiny | ||
} |
67 changes: 67 additions & 0 deletions
67
...server/src/main/java/org/apache/phoenix/queryserver/server/admin/AdminCommandRequest.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,67 @@ | ||
/* | ||
* 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.phoenix.queryserver.server.admin; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.htrace.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AdminCommandRequest { | ||
@JsonProperty(required = true) | ||
private AdminCommand command; | ||
private Map<String, String> parameters; | ||
|
||
public AdminCommandRequest() { | ||
|
||
} | ||
|
||
public AdminCommandRequest(AdminCommand command, Map<String, String> parameters) { | ||
this.command = command; | ||
this.parameters = parameters; | ||
} | ||
|
||
public AdminCommand getCommand() { | ||
return command; | ||
} | ||
|
||
public void setCommand(AdminCommand command) { | ||
this.command = command; | ||
} | ||
|
||
public Map<String, String> getParameters() { | ||
return parameters; | ||
} | ||
|
||
public void setParameters(Map<String, String> parameters) { | ||
this.parameters = parameters; | ||
} | ||
|
||
public String[] getParametersAsInputArgs() { | ||
String[] args = parameters != null ? new String[parameters.size()] : new String[0]; | ||
if (parameters != null) { | ||
int index = 0; | ||
for (String key : parameters.keySet()) { | ||
args[index++] = "-" + key + " " + parameters.get(key); | ||
} | ||
} | ||
return args; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...yserver/src/main/java/org/apache/phoenix/queryserver/server/admin/AdminServerHandler.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,73 @@ | ||
/* | ||
* 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.phoenix.queryserver.server.admin; | ||
|
||
|
||
import org.apache.hadoop.mapreduce.Job; | ||
import org.apache.hadoop.util.Tool; | ||
import org.apache.hadoop.util.ToolRunner; | ||
import org.apache.htrace.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.phoenix.mapreduce.index.IndexScrutinyTool; | ||
import org.eclipse.jetty.server.Handler; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.handler.AbstractHandler; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import org.apache.phoenix.mapreduce.index.IndexTool; | ||
/** | ||
* | ||
*/ | ||
public class AdminServerHandler extends AbstractHandler { | ||
@Override | ||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { | ||
if ("POST".equalsIgnoreCase(baseRequest.getMethod())) { | ||
response.setContentType("application/json"); | ||
try { | ||
AdminCommandRequest adminCommand = parseRequest(baseRequest.getInputStream()); | ||
response.setStatus(HttpServletResponse.SC_OK); | ||
Tool tool = null; | ||
switch (adminCommand.getCommand()) { | ||
case IndexTool: | ||
tool = new IndexTool(); | ||
break; | ||
case IndexScrutiny: | ||
tool = new IndexScrutinyTool(); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unsupported tool: " + adminCommand.getCommand()); | ||
} | ||
int runStatus = ToolRunner.run(tool, adminCommand.getParametersAsInputArgs()); | ||
} catch (Exception e) { | ||
|
||
} | ||
response.getWriter().println("<h1>Hello OneHandler</h1>"); | ||
response.flushBuffer(); | ||
} | ||
|
||
} | ||
|
||
private AdminCommandRequest parseRequest(InputStream inputStream) throws IOException { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
return mapper.readValue(inputStream, AdminCommandRequest.class); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...rc/main/java/org/apache/phoenix/queryserver/server/customizers/AdminServerCustomizer.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,39 @@ | ||
/* | ||
* 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.phoenix.queryserver.server.customizers; | ||
import org.apache.phoenix.queryserver.server.admin.AdminServerHandler; | ||
import org.eclipse.jetty.server.Handler; | ||
import org.eclipse.jetty.server.handler.ContextHandler; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AdminServerCustomizer extends ContextCustomizer { | ||
|
||
public AdminServerCustomizer(String contextPath) { | ||
super(contextPath); | ||
} | ||
|
||
@Override | ||
protected Handler createHandler(String contextPath) { | ||
ContextHandler ctx = new ContextHandler(contextPath); | ||
ctx.setAllowNullPathInfo(true); | ||
ctx.setHandler(new AdminServerHandler()); | ||
return ctx; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...er/src/main/java/org/apache/phoenix/queryserver/server/customizers/ContextCustomizer.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,63 @@ | ||
/* | ||
* 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.phoenix.queryserver.server.customizers; | ||
|
||
import org.apache.calcite.avatica.server.ServerCustomizer; | ||
import org.eclipse.jetty.server.Handler; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.handler.ContextHandler; | ||
import org.eclipse.jetty.server.handler.HandlerList; | ||
import org.eclipse.jetty.server.handler.ResourceHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* A context based customizer | ||
*/ | ||
public abstract class ContextCustomizer implements ServerCustomizer<Server> { | ||
private static final Logger LOG = LoggerFactory.getLogger(ContextCustomizer.class); | ||
|
||
private final String contextPath; | ||
|
||
/** | ||
* @param contextPath The HTTP path which the repository will be hosted at | ||
*/ | ||
protected ContextCustomizer(String contextPath) { | ||
this.contextPath = contextPath; | ||
} | ||
|
||
@Override | ||
public void customize(Server server) { | ||
Handler[] handlers = server.getHandlers(); | ||
if (handlers.length != 1) { | ||
LOG.warn("Observed handlers on server {}", Arrays.toString(handlers)); | ||
throw new IllegalStateException("Expected to find one handler"); | ||
} | ||
HandlerList list = (HandlerList) handlers[0]; | ||
Handler[] realHandlers = list.getChildHandlers(); | ||
Handler[] newHandlers = new Handler[realHandlers.length + 1]; | ||
newHandlers[0] = createHandler(contextPath); | ||
System.arraycopy(realHandlers, 0, newHandlers, 1, realHandlers.length); | ||
server.setHandler(new HandlerList(newHandlers)); | ||
} | ||
|
||
protected abstract Handler createHandler(String contextPath); | ||
} |
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
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.
Dont' use the HTrace jackson package.