From 2e96de2416e1030fe3dfb80903eac8ca9d192851 Mon Sep 17 00:00:00 2001 From: Yohann Paris Date: Tue, 11 Feb 2025 14:57:31 -0500 Subject: [PATCH] remove skema-py (#6565) --- .../controller/code/CodeController.java | 67 ------------------- .../hmiserver/proxies/skema/SkemaProxy.java | 19 ------ .../resources/application-staging.properties | 1 - .../src/main/resources/application.properties | 1 - 4 files changed, 88 deletions(-) delete mode 100644 packages/server/src/main/java/software/uncharted/terarium/hmiserver/proxies/skema/SkemaProxy.java diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/code/CodeController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/code/CodeController.java index d8f64ba6ee..b3aa1d4722 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/code/CodeController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/code/CodeController.java @@ -6,7 +6,6 @@ import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.text.StringEscapeUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; @@ -14,19 +13,14 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.access.annotation.Secured; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; -import software.uncharted.terarium.hmiserver.models.StoredModel; -import software.uncharted.terarium.hmiserver.models.code.CodeRequest; import software.uncharted.terarium.hmiserver.models.code.GithubFile; import software.uncharted.terarium.hmiserver.models.code.GithubRepo; import software.uncharted.terarium.hmiserver.proxies.github.GithubProxy; import software.uncharted.terarium.hmiserver.proxies.jsdelivr.JsDelivrProxy; -import software.uncharted.terarium.hmiserver.proxies.skema.SkemaProxy; -import software.uncharted.terarium.hmiserver.proxies.skema.SkemaRustProxy; import software.uncharted.terarium.hmiserver.security.Roles; @Slf4j @@ -39,67 +33,6 @@ public class CodeController { private final JsDelivrProxy jsdelivrProxy; - private final SkemaProxy skemaProxy; - - private final SkemaRustProxy skemaRustProxy; - - /** - * Stores a model from a code snippet - * - * @param code the python code snippet - * @return a {@link StoredModel} instance containing the model id, inputs, and outputs of the model derived from the - * code input - */ - @PostMapping - @Secured(Roles.USER) - @ApiResponses( - value = { - @ApiResponse(responseCode = "200", description = "Code transformed successfully"), - @ApiResponse(responseCode = "204", description = "No content") - } - ) - public ResponseEntity transformCode(final String code) { - // Convert from highlighted code a function network - final String skemaResponseStr; - try { - skemaResponseStr = skemaProxy.getFunctionNetwork(new CodeRequest(code)).getBody(); - } catch (final FeignException e) { - final String error = "Error creating function network from code"; - final int status = e.status() >= 400 ? e.status() : 500; - log.error(error, e); - throw new ResponseStatusException(org.springframework.http.HttpStatus.valueOf(status), error); - } - - if (skemaResponseStr == null || skemaResponseStr.isEmpty()) { - return ResponseEntity.noContent().build(); - } - - // The model is returned from Skema as escaped, quoted json. Eg: - // "{\"hello\": \"world\" .... }" - // We must remove the leading and trailing quotes, and un-escape the json in - // order to pass it on to the - // service that will store the model as it expects application/json and not a - // string - final String unescapedSkemaResponseStr = StringEscapeUtils.unescapeJson( - skemaResponseStr.substring(1, skemaResponseStr.length() - 1) - ); - - // Store the model - try { - final String modelId = skemaRustProxy.addModel(unescapedSkemaResponseStr).getBody(); - - final String odiResponseStr = skemaRustProxy.getModelNamedOpis(modelId).getBody(); - final String odoResponseStr = skemaRustProxy.getModelNamedOpos(modelId).getBody(); - - return ResponseEntity.ok(new StoredModel().setId(modelId).setInputs(odiResponseStr).setOutputs(odoResponseStr)); - } catch (final FeignException e) { - final String error = "transforming code to model failed"; - final int status = e.status() >= 400 ? e.status() : 500; - log.error(error, e); - throw new ResponseStatusException(org.springframework.http.HttpStatus.valueOf(status), error); - } - } - @GetMapping("/repo-content") @Secured(Roles.USER) @ApiResponses( diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/proxies/skema/SkemaProxy.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/proxies/skema/SkemaProxy.java deleted file mode 100644 index 8f9f7ed481..0000000000 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/proxies/skema/SkemaProxy.java +++ /dev/null @@ -1,19 +0,0 @@ -package software.uncharted.terarium.hmiserver.proxies.skema; - -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import software.uncharted.terarium.hmiserver.models.code.CodeRequest; - -@FeignClient(name = "skema-py", url = "${skema-py.url}") -public interface SkemaProxy { - /** - * Converts a {@link CodeRequest} to a function network via TA1 Skema - * - * @param request the {@link CodeRequest} instance containing the code snippit - * @return an escaped JSON string of the function network - */ - @PostMapping("/fn-given-filepaths") - ResponseEntity getFunctionNetwork(@RequestBody CodeRequest request); -} diff --git a/packages/server/src/main/resources/application-staging.properties b/packages/server/src/main/resources/application-staging.properties index e5bd33ab96..1a6272e40b 100644 --- a/packages/server/src/main/resources/application-staging.properties +++ b/packages/server/src/main/resources/application-staging.properties @@ -46,7 +46,6 @@ terarium.file-storage-s3-bucket-name=askem-staging-data-service ######################################################################################################################## # Microservice configuration ######################################################################################################################## -skema-py.url=https://skema-py.staging.terarium.ai skema-rs.url=https://skema-rs.staging.terarium.ai skema-unified.url=https://skema-unified.staging.terarium.ai ciemss-service.url=https://pyciemss.staging.terarium.ai diff --git a/packages/server/src/main/resources/application.properties b/packages/server/src/main/resources/application.properties index 2af7f9e326..5145ae6f39 100644 --- a/packages/server/src/main/resources/application.properties +++ b/packages/server/src/main/resources/application.properties @@ -172,7 +172,6 @@ terarium.static-index-path=askem-static-index github.url=https://api.github.com jsdelivr.url=https://cdn.jsdelivr.net mira-api.url=http://mira-epi-dkg-lb-dc1e19b273dedaa2.elb.us-east-1.amazonaws.com -skema-py.url=https://skema-py.staging.terarium.ai skema-rs.url=https://skema-rs.staging.terarium.ai skema-unified.url=https://skema-unified.staging.terarium.ai ciemss-service.url=https://pyciemss.staging.terarium.ai