Skip to content

Commit

Permalink
chore: remove deprecated analysis api handler
Browse files Browse the repository at this point in the history
  • Loading branch information
D-D-H committed Nov 17, 2023
1 parent 7370ec2 commit c636aa8
Showing 1 changed file with 0 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@

import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jifa.common.domain.exception.ShouldNotReachHereException;
import org.eclipse.jifa.common.util.ExecutorFactory;
import org.eclipse.jifa.common.util.Validate;
import org.eclipse.jifa.server.ConfigurationAccessor;
import org.eclipse.jifa.server.Constant;
import org.eclipse.jifa.server.domain.dto.AnalysisApiRequest;
import org.eclipse.jifa.server.service.AnalysisApiService;
import org.eclipse.jifa.server.util.ControllerUtil;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

Expand All @@ -44,9 +36,6 @@

import static java.util.Optional.ofNullable;
import static org.eclipse.jifa.common.util.GsonHolder.GSON;
import static org.eclipse.jifa.server.Constant.ANALYSIS_API_REQUEST_API_KEY;
import static org.eclipse.jifa.server.Constant.ANALYSIS_API_REQUEST_NAMESPACE_KEY;
import static org.eclipse.jifa.server.Constant.ANALYSIS_API_REQUEST_TARGET_KEY;

@Slf4j
@RestController
Expand Down Expand Up @@ -74,42 +63,6 @@ public Object handleRequest(@RequestHeader(name = HttpHeaders.CONTENT_TYPE) Stri
return postProcess(apiService.invoke(new AnalysisApiRequest(request)), enableSse);
}

@Deprecated
@RequestMapping(path = "/{*api}",
method = {RequestMethod.POST, RequestMethod.GET},
consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE, MediaType.APPLICATION_JSON_VALUE},
produces = Constant.APPLICATION_JSON)
public Object handleRequest(
@PathVariable String api,
HttpMethod method,
@RequestHeader(name = HttpHeaders.CONTENT_TYPE, required = false, defaultValue = Constant.APPLICATION_JSON) String contentType,
@RequestHeader(name = Constant.HTTP_HEADER_ENABLE_SSE, required = false, defaultValue = "false") boolean enableSse,
@RequestParam(required = false) MultiValueMap<String, String> params,
@RequestBody(required = false) byte[] body) {

if (api == null || !api.startsWith("/")) {
throw new IllegalArgumentException("Unsupported api: " + api);
}

api = api.substring(1);

JsonObject args = null;
if (method == HttpMethod.GET) {
if (params != null && params.size() > 0) {
args = ControllerUtil.convertMultiValueMapToJsonObject(params);
}
} else if (method == HttpMethod.POST) {
MimeType mimeType = ControllerUtil.checkMimeTypeForPostRequest(contentType);
args = ControllerUtil.parseArgs(mimeType, body);
} else {
throw new ShouldNotReachHereException();
}

Validate.isTrue(isDeprecatedFormat(api));

return postProcess(apiService.invoke(new AnalysisApiRequest(processDeprecatedFormat(api, args))), enableSse);
}

private Object postProcess(CompletableFuture<?> future, boolean enableSse) {
if (!enableSse) {
return future;
Expand All @@ -134,29 +87,6 @@ private Object postProcess(CompletableFuture<?> future, boolean enableSse) {
return emitter;
}

private boolean isDeprecatedFormat(String api) {
return api.startsWith("heap-dump/") || api.startsWith("gc-log/") || api.startsWith("thread-dump/");
}

private JsonObject processDeprecatedFormat(String api, JsonObject args) {
JsonObject request = new JsonObject();

String[] elements = api.split("/");
Validate.isTrue(elements.length > 2);
request.addProperty(ANALYSIS_API_REQUEST_NAMESPACE_KEY, elements[0]);
request.addProperty(ANALYSIS_API_REQUEST_TARGET_KEY, elements[1]);
StringBuilder realApi = new StringBuilder(elements[2]);
for (int i = 3; i < elements.length; i++) {
realApi.append(".").append(elements[i]);
}
request.addProperty(ANALYSIS_API_REQUEST_API_KEY, realApi.toString());

if (args != null) {
request.add(Constant.ANALYSIS_API_REQUEST_PARAMETERS_KEY, args);
}
return request;
}

private class ExtendedSseEmitter extends SseEmitter implements Runnable {

public ExtendedSseEmitter() {
Expand Down

0 comments on commit c636aa8

Please sign in to comment.