in src/api-server/src/main/java/com/google/abmedge/apiserver/ApiServerController.java [150:177]
public ResponseEntity<Void> switchType(@PathVariable String type) {
String switchEndpoint = INVENTORY_SERVICE + SWITCH_EP + "/" + type;
try {
HttpRequest request =
HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.noBody())
.uri(URI.create(switchEndpoint))
.build();
HttpResponse<String> response =
HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
int statusCode = response.statusCode();
if (statusCode == HttpStatus.OK.value() || statusCode == HttpStatus.NO_CONTENT.value()) {
return new ResponseEntity<>(HttpStatus.OK);
}
LOGGER.error(
String.format(
"Failed to switch active inventory type to '%s' via endpoint '%s'."
+ " Status code '%s'",
type, switchEndpoint, statusCode));
} catch (IOException | InterruptedException e) {
LOGGER.error(
String.format(
"Failed to switch active inventory type to '%s' via endpoint '%s'.",
type, switchEndpoint),
e);
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}