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 33d320c144 rhub session impl and some refactoring
33d320c144 is described below

commit 33d320c1448615c24453c6a4e63d79b6dc254496
Author: lahiruj <[email protected]>
AuthorDate: Mon Mar 31 13:40:51 2025 -0400

    rhub session impl and some refactoring
---
 .../service/controller/ResearchHubController.java  | 31 ++++++++-------
 .../research/service/handlers/ProjectHandler.java  | 12 ++++--
 .../service/handlers/ResearchHubHandler.java       | 42 ++++++++++++++++++++
 .../research/service/handlers/SessionHandler.java  | 45 ++++++++++++++++++++++
 .../research/service/model/entity/User.java        | 11 ++++++
 .../{ProjectRepo.java => ProjectRepository.java}   |  2 +-
 .../service/model/repo/ResourceRepository.java     | 20 +++++++++-
 .../{ProjectRepo.java => SessionRepository.java}   |  6 +--
 .../research/service/model/repo/TagRepository.java | 21 +++++++++-
 .../service/model/repo/UserRepository.java         | 22 ++++++++++-
 10 files changed, 188 insertions(+), 24 deletions(-)

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 d5a348392e..04e40858e1 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
@@ -18,10 +18,10 @@
  */
 package org.apache.airavata.research.service.controller;
 
-import org.apache.airavata.research.service.model.UserContext;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.airavata.research.service.handlers.ResearchHubHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -30,29 +30,34 @@ 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")
+@Tag(name = "Research Hub", description = "Research Hub Operations")
 public class ResearchHubController {
 
     private static final Logger LOGGER = 
LoggerFactory.getLogger(ResearchHubController.class);
 
-    @Value("${cybershuttle.hub.url}")
-    private String csHubUrl;
+    private final ResearchHubHandler rHubHandler;
 
-    @GetMapping("/project/{projectId}")
-    public ResponseEntity<?> resolveResearchHubUrl(@PathVariable("projectId") 
String projectId) {
+    public ResearchHubController(ResearchHubHandler rHubHandler) {
+        this.rHubHandler = rHubHandler;
+    }
 
-        // TODO extract the data using the projectId
-        String gitUrl = "https://github.com/AllenInstitute/bmtk-workshop.git";;
-        String dataPath = "bmtk";
-        String randomSessionName = "session-" + 
UUID.randomUUID().toString().substring(0, 6);
-        System.out.println("Session: " + randomSessionName);
-        String spawnUrl = 
String.format("%s/hub/spawn/%s/%s?git=%s&dataPath=%s", csHubUrl, 
UserContext.username(), randomSessionName, gitUrl, dataPath);
+    @GetMapping("/project/{projectId}")
+    public ResponseEntity<?> resolveRHubUrl(@PathVariable("projectId") String 
projectId) {
+        String spawnUrl = rHubHandler.spinRHubSession(projectId);
 
         LOGGER.info("Redirecting user to spawn URL: {}", spawnUrl);
         return 
ResponseEntity.status(HttpStatus.FOUND).location(URI.create(spawnUrl)).build();
     }
+
+    @GetMapping("/session/{sessionId}")
+    public ResponseEntity<?> 
resolveRHubExistingSession(@PathVariable("sessionId") String sessionId) {
+        String spawnUrl = rHubHandler.resolveRHubExistingSession(sessionId);
+
+        LOGGER.info("Redirecting to existing session spawn URL: {}", spawnUrl);
+        return 
ResponseEntity.status(HttpStatus.FOUND).location(URI.create(spawnUrl)).build();
+    }
 }
 
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ProjectHandler.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ProjectHandler.java
index 0574262173..224dc95235 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ProjectHandler.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ProjectHandler.java
@@ -20,24 +20,30 @@ package org.apache.airavata.research.service.handlers;
 
 import org.apache.airavata.research.service.ResponseTypes.ResourceResponse;
 import org.apache.airavata.research.service.enums.ResourceTypeEnum;
-import org.apache.airavata.research.service.model.entity.*;
+import org.apache.airavata.research.service.model.entity.DatasetResource;
+import org.apache.airavata.research.service.model.entity.ModelResource;
+import org.apache.airavata.research.service.model.entity.NotebookResource;
+import org.apache.airavata.research.service.model.entity.RepositoryResource;
+import org.apache.airavata.research.service.model.entity.Resource;
+import org.apache.airavata.research.service.model.entity.Tag;
+import org.apache.airavata.research.service.model.entity.User;
 import org.apache.airavata.research.service.model.repo.ResourceRepository;
 import org.apache.airavata.research.service.model.repo.TagRepository;
 import org.apache.airavata.research.service.model.repo.UserRepository;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
 
 import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
 
[email protected]
+@Service
 public class ProjectHandler {
 
     private static final Logger LOGGER = 
LoggerFactory.getLogger(ProjectHandler.class);
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResearchHubHandler.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResearchHubHandler.java
index 6e88b6ffee..eae2cb1b11 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResearchHubHandler.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/ResearchHubHandler.java
@@ -18,5 +18,47 @@
  */
 package org.apache.airavata.research.service.handlers;
 
+import org.apache.airavata.research.service.model.UserContext;
+import org.apache.airavata.research.service.model.entity.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.UUID;
+
+@Service
 public class ResearchHubHandler {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ResearchHubHandler.class);
+    private static final String RH_SPAWN_URL = 
"%s/hub/spawn/%s/%s?git=%s&dataPath=%s";
+    private static final String RH_SESSION_URL = "%s/hub/spawn/%s/%s";
+
+    private final ProjectHandler projectHandler;
+    private final SessionHandler sessionHandler;
+
+    @Value("${cybershuttle.hub.url}")
+    private String csHubUrl;
+
+    public ResearchHubHandler(ProjectHandler projectHandler, SessionHandler 
sessionHandler) {
+        this.projectHandler = projectHandler;
+        this.sessionHandler = sessionHandler;
+    }
+
+    public String spinRHubSession(String projectId) {
+        // TODO fix the conflict of Project vs Resource
+        // TODO extract the data using the projectId
+        String gitUrl = "https://github.com/AllenInstitute/bmtk-workshop.git";;
+        String dataPath = "bmtk";
+        String randomSessionName = "session-" + 
UUID.randomUUID().toString().substring(0, 6);
+        System.out.println("Session: " + randomSessionName);
+        return String.format(RH_SPAWN_URL, csHubUrl, UserContext.username(), 
randomSessionName, gitUrl, dataPath);
+    }
+
+    public String resolveRHubExistingSession(String sessionId) {
+        LOGGER.debug("Resolving RH session id {} for user: {}", sessionId, 
UserContext.username());
+        // TODO restrict this execution for owner
+        Session session = sessionHandler.findSession(sessionId);
+        return String.format(RH_SESSION_URL, csHubUrl, UserContext.username(), 
session.getId());
+    }
 }
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/SessionHandler.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/SessionHandler.java
new file mode 100644
index 0000000000..367380c867
--- /dev/null
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/handlers/SessionHandler.java
@@ -0,0 +1,45 @@
+/**
+ * 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.handlers;
+
+import jakarta.persistence.EntityNotFoundException;
+import org.apache.airavata.research.service.model.entity.Session;
+import org.apache.airavata.research.service.model.repo.SessionRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SessionHandler {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SessionHandler.class);
+
+    private final SessionRepository sessionRepository;
+
+    public SessionHandler(SessionRepository sessionRepository) {
+        this.sessionRepository = sessionRepository;
+    }
+
+    public Session findSession(String sessionId) {
+        return sessionRepository.findById(sessionId).orElseThrow(() -> {
+            LOGGER.error("Unable to find session with id: " + sessionId);
+            return new EntityNotFoundException("Unable to find session with 
id: " + sessionId);
+        });
+    }
+}
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/entity/User.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/entity/User.java
index d7c9f664f4..3a362bd5b3 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/entity/User.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/entity/User.java
@@ -41,6 +41,9 @@ public class User {
     @Column(nullable = false, updatable = false, length = 48)
     private String id;
 
+    @Column(nullable = false)
+    private String username;
+
     @Column(nullable = false)
     private String firstName;
 
@@ -71,6 +74,14 @@ public class User {
         this.id = id;
     }
 
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
     public String getFirstName() {
         return firstName;
     }
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepo.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepository.java
similarity index 93%
copy from 
modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepo.java
copy to 
modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepository.java
index 5fd67a201e..9dec82ea01 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepo.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepository.java
@@ -23,5 +23,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
 @Repository
-public interface ProjectRepo extends JpaRepository<Project, String> {
+public interface ProjectRepository extends JpaRepository<Project, String> {
 }
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceRepository.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceRepository.java
index 94005a0c13..72daa3c787 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceRepository.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ResourceRepository.java
@@ -1,3 +1,21 @@
+/**
+ * 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.model.repo;
 
 import org.apache.airavata.research.service.model.entity.Resource;
@@ -10,9 +28,9 @@ import org.springframework.stereotype.Repository;
 
 import java.util.List;
 
-
 @Repository
 public interface ResourceRepository extends JpaRepository<Resource, String> {
+
     @Query("SELECT r FROM #{#entityName} r WHERE TYPE(r) IN :types")
     Page<Resource> findAllByTypes(@Param("types") List<Class<? extends 
Resource>> types, Pageable pageable);
 }
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepo.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/SessionRepository.java
similarity index 82%
rename from 
modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepo.java
rename to 
modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/SessionRepository.java
index 5fd67a201e..1292613150 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/ProjectRepo.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/SessionRepository.java
@@ -18,10 +18,8 @@
  */
 package org.apache.airavata.research.service.model.repo;
 
-import org.apache.airavata.research.service.model.entity.Project;
+import org.apache.airavata.research.service.model.entity.Session;
 import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
 
-@Repository
-public interface ProjectRepo extends JpaRepository<Project, String> {
+public interface SessionRepository extends JpaRepository<Session, String> {
 }
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/TagRepository.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/TagRepository.java
index 328c2431d8..2ed46b24ec 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/TagRepository.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/TagRepository.java
@@ -1,8 +1,27 @@
+/**
+ * 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.model.repo;
+
 import org.apache.airavata.research.service.model.entity.Tag;
 import org.springframework.data.jpa.repository.JpaRepository;
-import org.apache.airavata.research.service.model.entity.NotebookResource;
 
 public interface TagRepository extends JpaRepository<Tag, String> {
+
     Tag findByValue(String value);
 }
diff --git 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/UserRepository.java
 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/UserRepository.java
index f565d58b79..b0ee4f21be 100644
--- 
a/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/UserRepository.java
+++ 
b/modules/research-framework/research-service/src/main/java/org/apache/airavata/research/service/model/repo/UserRepository.java
@@ -1,9 +1,29 @@
+/**
+ * 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.model.repo;
 
-import org.springframework.data.jpa.repository.JpaRepository;
 import org.apache.airavata.research.service.model.entity.User;
+import org.springframework.data.jpa.repository.JpaRepository;
 
 public interface UserRepository extends JpaRepository<User, String> {
+
     boolean existsByEmail(String email);
+
     User findByEmail(String email);
 }

Reply via email to