Skip to content

Commit

Permalink
Fixed code format
Browse files Browse the repository at this point in the history
  • Loading branch information
estherbuchwalter committed Mar 9, 2022
1 parent a23a627 commit 21e50d7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@
import java.util.ArrayList;
import java.util.List;

@OpenAPIDefinition(info = @Info(title = "Apache Drill REST API", description = "OpenAPI Specification", license = @License(name = "Apache Software Foundation (ASF)", url = "http://www.apache" + ".org/licenses/LICENSE-2.0"), contact = @Contact(name = "Apache Drill", url = "https://drill.apache.org/")))/*,
tags = {
@Tag(name = "My Tag 1", description = "Tag 1's Description", externalDocs = @ExternalDocumentation(description = "docs description1")),
@Tag(name = "My Tag 2", description = "Tag 2's Description", externalDocs = @ExternalDocumentation(description = "docs description2"))})*/
@OpenAPIDefinition(info = @Info(title = "Apache Drill REST API", description = "OpenAPI Specification",
license = @License(name = "Apache Software Foundation (ASF)", url = "http://www.apache" + ".org/licenses/LICENSE-2.0"),
contact = @Contact(name = "Apache Drill", url = "https://drill.apache.org/")))

public class DrillRestServer extends ResourceConfig {
static final Logger logger = LoggerFactory.getLogger(DrillRestServer.class);
Expand Down Expand Up @@ -204,7 +203,9 @@ public WebUserConnection provide() {
// User is login in for the first time
final DrillbitContext drillbitContext = workManager.getContext();
final DrillConfig config = drillbitContext.getConfig();
final UserSession drillUserSession = UserSession.Builder.newBuilder().withCredentials(UserBitShared.UserCredentials.newBuilder().setUserName(sessionUserPrincipal.getName()).build()).withOptionManager(drillbitContext.getOptionManager()).setSupportComplexTypes(config.getBoolean(ExecConstants.CLIENT_SUPPORT_COMPLEX_TYPES)).build();
final UserSession drillUserSession = UserSession.Builder.newBuilder().withCredentials(UserBitShared.UserCredentials.newBuilder()
.setUserName(sessionUserPrincipal.getName()).build()).withOptionManager(drillbitContext.getOptionManager())
.setSupportComplexTypes(config.getBoolean(ExecConstants.CLIENT_SUPPORT_COMPLEX_TYPES)).build();

// Only try getting remote address in first login since it's a costly operation.
SocketAddress remoteAddress = null;
Expand All @@ -219,7 +220,9 @@ public WebUserConnection provide() {

// Create per session BufferAllocator and set it in session
final String sessionAllocatorName = String.format("WebServer:AuthUserSession:%s", session.getId());
final BufferAllocator sessionAllocator = workManager.getContext().getAllocator().newChildAllocator(sessionAllocatorName, config.getLong(ExecConstants.HTTP_SESSION_MEMORY_RESERVATION), config.getLong(ExecConstants.HTTP_SESSION_MEMORY_MAXIMUM));
final BufferAllocator sessionAllocator = workManager.getContext().getAllocator()
.newChildAllocator(sessionAllocatorName, config.getLong(ExecConstants.HTTP_SESSION_MEMORY_RESERVATION),
config.getLong(ExecConstants.HTTP_SESSION_MEMORY_MAXIMUM));

// Create a future which is needed by Foreman only. Foreman uses this future to add a close
// listener to known about channel close event from underlying layer. We use this future to notify Foreman
Expand Down Expand Up @@ -258,12 +261,15 @@ public WebUserConnection provide() {
final DrillConfig config = drillbitContext.getConfig();

// Create an allocator here for each request
final BufferAllocator sessionAllocator = drillbitContext.getAllocator().newChildAllocator("WebServer:AnonUserSession", config.getLong(ExecConstants.HTTP_SESSION_MEMORY_RESERVATION), config.getLong(ExecConstants.HTTP_SESSION_MEMORY_MAXIMUM));
final BufferAllocator sessionAllocator = drillbitContext.getAllocator().newChildAllocator("WebServer:AnonUserSession",
config.getLong(ExecConstants.HTTP_SESSION_MEMORY_RESERVATION), config.getLong(ExecConstants.HTTP_SESSION_MEMORY_MAXIMUM));

final Principal sessionUserPrincipal = createSessionUserPrincipal(config, request);

// Create new UserSession for each request from non-authenticated user
final UserSession drillUserSession = UserSession.Builder.newBuilder().withCredentials(UserBitShared.UserCredentials.newBuilder().setUserName(sessionUserPrincipal.getName()).build()).withOptionManager(drillbitContext.getOptionManager()).setSupportComplexTypes(drillbitContext.getConfig().getBoolean(ExecConstants.CLIENT_SUPPORT_COMPLEX_TYPES)).build();
final UserSession drillUserSession = UserSession.Builder.newBuilder().withCredentials(UserBitShared.UserCredentials.newBuilder()
.setUserName(sessionUserPrincipal.getName()).build()).withOptionManager(drillbitContext.getOptionManager())
.setSupportComplexTypes(drillbitContext.getConfig().getBoolean(ExecConstants.CLIENT_SUPPORT_COMPLEX_TYPES)).build();

// Try to get the remote Address but set it to null in case of failure.
SocketAddress remoteAddress = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public Response getDrillbitStatus() {
@Path("/gracePeriod")
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = " https://drill.apache.org/docs/stopping-drill/#:~:text=draining%2C%20and%20offline.%0A%20%20%20%20%20--,grace,-%3A%20A%20period%20in"))

public Map<String, Integer> getGracePeriod() {
final DrillConfig config = work.getContext().getConfig();
final int gracePeriod = config.getInt(ExecConstants.GRACE_PERIOD);
Expand All @@ -135,7 +134,6 @@ public Map<String, Integer> getPortNum() {
@Path("/queriesCount")
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/apidocs/org/apache/drill/exec/work/WorkManager.html#:~:text=waitToExit(boolean%C2%A0forcefulShutdown)-,getremainingqueries,-public%C2%A0Map%3CString"))

public Response getRemainingQueries() {
Map<String, Integer> queriesInfo = work.getRemainingQueries();
return setResponse(queriesInfo);
Expand All @@ -146,7 +144,6 @@ public Response getRemainingQueries() {
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN_ROLE)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/stopping-drill/"))

public Response shutdownDrillbit() throws Exception {
String resp = "Graceful Shutdown request is triggered";
return shutdown(resp);
Expand All @@ -157,7 +154,6 @@ public Response shutdownDrillbit() throws Exception {
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN_ROLE)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/stopping-drill/"))

public String shutdownDrillbitByName(@PathParam("hostname") String hostname) throws Exception {
URL shutdownURL = WebUtils.getDrillbitURL(work, request, hostname, "/gracefulShutdown");
return WebUtils.doHTTPRequest(new HttpPost(shutdownURL.toURI()), work.getContext().getConfig());
Expand All @@ -168,7 +164,6 @@ public String shutdownDrillbitByName(@PathParam("hostname") String hostname) thr
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN_ROLE)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/stopping-drill/"))

public Response shutdownForcefully() throws Exception {
drillbit.setForcefulShutdown(true);
String resp = "Forceful shutdown request is triggered";
Expand All @@ -180,7 +175,6 @@ public Response shutdownForcefully() throws Exception {
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN_ROLE)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/stopping-drill/"))

public Response drillbitToQuiescentMode() throws Exception {
drillbit.setQuiescentMode(true);
String resp = "Request to put drillbit in Quiescent mode is triggered";
Expand All @@ -191,7 +185,6 @@ public Response drillbitToQuiescentMode() throws Exception {
@Path("/cluster.json")
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=Gets%20metric%20information.-,get%20%2Fcluster.json,-Get%20Drillbit%20information"))

public ClusterInfo getClusterInfoJSON() {
final Collection<DrillbitInfo> drillbits = Sets.newTreeSet();
final Collection<String> mismatchedVersions = Sets.newTreeSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public class QueryResources {
@Path("/query")
@Produces(MediaType.TEXT_HTML)
public Viewable getQuery() {
List<StorageResources.StoragePluginModel> enabledPlugins = sr.getConfigsFor("enabled").stream().map(plugin -> new StorageResources.StoragePluginModel(plugin, request)).collect(Collectors.toList());
List<StorageResources.StoragePluginModel> enabledPlugins =
sr.getConfigsFor("enabled").stream().map(plugin -> new StorageResources.StoragePluginModel(plugin, request)).collect(Collectors.toList());
return ViewableWithPermissions.create(authEnabled.get(), "/rest/query/query.ftl", sc, new QueryPage(work, enabledPlugins, request));
}

Expand All @@ -94,7 +95,6 @@ public Viewable getQuery() {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache" + ".org/docs/rest-api-introduction/#:~:text=programmatically%20run%20queries.-,post%20%2Fquery.json,-Submit%20a%20query"))

public StreamingOutput submitQueryJSON(QueryWrapper query) throws Exception {

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public class StatusResources {
@Path(StatusResources.PATH_STATUS_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=Memory%22%2C%0A%20%20%20%20%20%20%22value%22%20%3A%208589934592%0A%20%20%20%20%7D%20%5D-,get%20%2Fstatus,-Get%20the%20status"))

public Pair<String, String> getStatusJSON() {
return new ImmutablePair<>("status", "Running!");
}
Expand All @@ -117,7 +116,6 @@ public Viewable getStatus() {
@Path(StatusResources.PATH_METRICS + "/{hostname}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=Running!%3C%2Fstrong%3E%0A%20%20%20%20%20%20.%20.%20.%0A%0A%20%20%20%20%20%20%3C%2Fhtml%3E-,get%20%2Fstatus%2Fmetrics,-Get%20the%20current"))

public String getMetrics(@PathParam("hostname") String hostname) throws Exception {
URL metricsURL = WebUtils.getDrillbitURL(work, request, hostname, StatusResources.PATH_METRICS);
return WebUtils.doHTTPRequest(new HttpGet(metricsURL.toURI()), work.getContext().getConfig());
Expand Down Expand Up @@ -146,7 +144,6 @@ public int compare(OptionWrapper o1, OptionWrapper o2) {
@RolesAllowed(DrillUserPrincipal.AUTHENTICATED_ROLE)
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=gets%20system%20options.-,get%20%2Foptions.json,-List%20the%20name"))

public List<OptionWrapper> getSystemPublicOptionsJSON() {
return getSystemOptionsJSONHelper(false);
}
Expand Down Expand Up @@ -260,7 +257,9 @@ public static class OptionWrapper {
private String optionScope;

@JsonCreator
public OptionWrapper(@JsonProperty("name") String name, @JsonProperty("value") Object value, @JsonProperty("defaultValue") String defaultValue, @JsonProperty("accessibleScopes") OptionValue.AccessibleScopes type, @JsonProperty("kind") Kind kind, @JsonProperty("optionScope") OptionValue.OptionScope scope) {
public OptionWrapper(@JsonProperty("name") String name, @JsonProperty("value") Object value,
@JsonProperty("defaultValue") String defaultValue, @JsonProperty("accessibleScopes") OptionValue.AccessibleScopes type,
@JsonProperty("kind") Kind kind, @JsonProperty("optionScope") OptionValue.OptionScope scope) {
this.name = name;
this.value = value;
this.defaultValue = defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public Response getConfigsFor(@PathParam("group") String pluginGroup, @PathParam
@Path("/storage.json")
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=storage%20plugin%20configurations.-,get%20%2Fstorage.json,-Get%20the%20list"))

public List<PluginConfigWrapper> getPluginsJSON() {
return getConfigsFor(ALL_PLUGINS);
}
Expand All @@ -154,9 +153,8 @@ public Viewable getPlugins() {

@GET
@Path("/storage/{name}.json")
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=get%20%2Fstorage%2F%7Bname%7D.json"))

@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=get%20%2Fstorage%2F%7Bname%7D.json"))
public Response getPluginConfig(@PathParam("name") String name) {
try {
return Response.ok(new PluginConfigWrapper(name, storage.getStoredConfig(name))).build();
Expand All @@ -180,7 +178,6 @@ public Viewable getPlugin(@PathParam("name") String name) {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=get%20%2Fstorage%2F%7Bname%7D%2Fenable%2F%7Bval%7D"))

public Response enablePlugin(@PathParam("name") String name, @PathParam("val") Boolean enable) {
try {
storage.setEnabled(name, enable);
Expand Down Expand Up @@ -326,7 +323,6 @@ public Response updateAuthToken(@PathParam("name") String name, @QueryParam("cod
@Path("/storage/{name}/enable/{val}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=get%20%2Fstorage%2F%7Bname%7D%2Fenable%2F%7Bval%7D"))

@Deprecated
public Response enablePluginViaGet(@PathParam("name") String name, @PathParam("val") Boolean enable) {
return enablePlugin(name, enable);
Expand Down Expand Up @@ -354,7 +350,6 @@ public Response exportPlugin(@PathParam("name") String name, @PathParam("format"
@Path("/storage/{name}.json")
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=DELETE%20%2Fstorage%2F%7Bname,storage%20plugin%20configuration."))

public Response deletePlugin(@PathParam("name") String name) {
try {
TokenRegistry tokenRegistry = ((AbstractStoragePlugin) storage.getPlugin(name)).getContext().getoAuthTokenProvider().getOauthTokenRegistry();
Expand All @@ -374,7 +369,6 @@ public Response deletePlugin(@PathParam("name") String name) {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/rest-api-introduction/#:~:text=post%20%2Fstorage%2F%7Bname%7D.json"))

public Response createOrUpdatePluginJSON(PluginConfigWrapper plugin) {
try {
plugin.createOrUpdateInStorage(storage);
Expand Down

0 comments on commit 21e50d7

Please sign in to comment.