This is an automated email from the ASF dual-hosted git repository.

lahirujayathilake pushed a commit to branch cybershuttle-staging
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/cybershuttle-staging by this 
push:
     new 9d4b8c68f4 global exception handler and boiler template for spinning 
up a new JL cloning a git repo and mounting ro volume
9d4b8c68f4 is described below

commit 9d4b8c68f49f5493f83b9b958ceb237467b5209b
Author: lahiruj <[email protected]>
AuthorDate: Sun Mar 30 18:57:13 2025 -0400

    global exception handler and boiler template for spinning up a new JL 
cloning a git repo and mounting ro volume
---
 .../controller/GlobalExceptionController.java      | 57 ++++++++++++++++++++++
 .../service/controller/ResearchHubController.java  | 28 ++++++++++-
 2 files changed, 84 insertions(+), 1 deletion(-)

diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/GlobalExceptionController.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/GlobalExceptionController.java
new file mode 100644
index 0000000000..af053d40a4
--- /dev/null
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/GlobalExceptionController.java
@@ -0,0 +1,57 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.airavata.research.service.controller;
+
+import jakarta.persistence.EntityNotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+@ControllerAdvice
+public class GlobalExceptionController {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(GlobalExceptionController.class);
+
+    @ExceptionHandler(IllegalArgumentException.class)
+    public ResponseEntity<String> 
handleIllegalArgumentException(IllegalArgumentException ex) {
+        LOGGER.error("Illegal argument error: ", ex);
+        return ResponseEntity
+                .status(HttpStatus.BAD_REQUEST)
+                .body(ex.getMessage());
+    }
+
+    @ExceptionHandler(EntityNotFoundException.class)
+    public ResponseEntity<String> 
handleEntityNotFoundException(EntityNotFoundException ex) {
+        LOGGER.error("Entity not found: ", ex);
+        return ResponseEntity
+                .status(HttpStatus.NOT_FOUND)
+                .body(ex.getMessage());
+    }
+
+    @ExceptionHandler(Exception.class)
+    public ResponseEntity<String> handleOtherExceptions(Exception ex) {
+        LOGGER.error("Unexpected error occurred: ", ex);
+        return ResponseEntity
+                .status(HttpStatus.INTERNAL_SERVER_ERROR)
+                .body("Unexpected error occurred");
+    }
+}
\ No newline at end of file
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/ResearchHubController.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/ResearchHubController.java
index 0b37e84af1..f4b17e1bc4 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/ResearchHubController.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/controller/ResearchHubController.java
@@ -20,15 +20,41 @@ package org.apache.airavata.research.service.controller;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.net.URI;
+import java.util.UUID;
+
 @RestController
 @RequestMapping("/api/v1/rf/hub")
 public class ResearchHubController {
 
     private static final Logger LOGGER = 
LoggerFactory.getLogger(ResearchHubController.class);
 
-// open up the jupyterhub resolving the yml file configs
+    @GetMapping("/project/{projectId}")
+    public ResponseEntity<?> resolveResearchHubUrl(@PathVariable("projectId") 
String projectId) {
+
+        // TODO extract the data using the projectId
+        String gitUrl = "https://github.com/AllenInstitute/bmtk-workshop.git";;
+        String dataPath = "bmtk";
+        String jupyterUser = "[email protected]";
+        String randomSessionName = "session-" + 
UUID.randomUUID().toString().substring(0, 6);
+        System.out.println();
+        String spawnUrl = String.format(
+                
"https://hub.dev.cybershuttle.org/hub/spawn/%s/%s?git=%s&dataPath=%s";,
+                jupyterUser,
+                randomSessionName,
+                gitUrl,
+                dataPath
+        );
+
+        LOGGER.info("Redirecting user to spawn URL: {}", spawnUrl);
+        return 
ResponseEntity.status(HttpStatus.FOUND).location(URI.create(spawnUrl)).build();
+    }
 }
 

Reply via email to