You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2026/08/07 04:26:16 UTC

(airavata) branch refactor-single-module updated: Integrating slurm cluster with app deployment

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

DImuthuUpe pushed a commit to branch refactor-single-module
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/refactor-single-module by this push:
     new 3b784ec176 Integrating slurm cluster with app deployment
3b784ec176 is described below

commit 3b784ec1762f6ff35a8f5b63096bf942bd8f11b0
Author: DImuthuUpe <di...@gmail.com>
AuthorDate: Fri Aug 7 00:26:11 2026 -0400

    Integrating slurm cluster with app deployment
---
 .../mapper/SlurmApplicationDeploymentMapper.java     |  8 ++++++--
 .../deployment/SlurmApplicationDeploymentEntity.java | 17 ++++++++---------
 .../service/SlurmApplicationDeploymentService.java   | 20 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/airavata/application/mapper/SlurmApplicationDeploymentMapper.java b/src/main/java/org/apache/airavata/application/mapper/SlurmApplicationDeploymentMapper.java
index 4f9a9c015d..a20209c5c7 100644
--- a/src/main/java/org/apache/airavata/application/mapper/SlurmApplicationDeploymentMapper.java
+++ b/src/main/java/org/apache/airavata/application/mapper/SlurmApplicationDeploymentMapper.java
@@ -9,20 +9,24 @@ import org.mapstruct.MappingTarget;
 import org.mapstruct.ReportingPolicy;
 
 /**
- * Entity/DTO conversions for Slurm deployments. The template association is resolved by
- * the service from {@code templateId}, so it is never mapped straight off the request.
+ * Entity/DTO conversions for Slurm deployments. Both associations — the application
+ * template and the Slurm cluster — are resolved by the service from their ids, so
+ * neither is ever mapped straight off the request.
  */
 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
 public interface SlurmApplicationDeploymentMapper {
 
     @Mapping(target = "templateId", source = "applicationTemplate.templateId")
+    @Mapping(target = "slurmClusterId", source = "slurmCluster.clusterId")
     SlurmApplicationDeploymentResponseDto toResponseDto(SlurmApplicationDeploymentEntity entity);
 
     @Mapping(target = "deploymentId", ignore = true)
     @Mapping(target = "applicationTemplate", ignore = true)
+    @Mapping(target = "slurmCluster", ignore = true)
     SlurmApplicationDeploymentEntity toEntity(SlurmApplicationDeploymentRequestDto dto);
 
     @Mapping(target = "deploymentId", ignore = true)
     @Mapping(target = "applicationTemplate", ignore = true)
+    @Mapping(target = "slurmCluster", ignore = true)
     void updateEntity(SlurmApplicationDeploymentRequestDto dto, @MappingTarget SlurmApplicationDeploymentEntity entity);
 }
diff --git a/src/main/java/org/apache/airavata/application/model/deployment/SlurmApplicationDeploymentEntity.java b/src/main/java/org/apache/airavata/application/model/deployment/SlurmApplicationDeploymentEntity.java
index f50e620da8..547e402341 100644
--- a/src/main/java/org/apache/airavata/application/model/deployment/SlurmApplicationDeploymentEntity.java
+++ b/src/main/java/org/apache/airavata/application/model/deployment/SlurmApplicationDeploymentEntity.java
@@ -1,6 +1,7 @@
 package org.apache.airavata.application.model.deployment;
 
 import org.apache.airavata.application.model.template.ApplicationTemplateEntity;
+import org.apache.airavata.compute.model.SlurmClusterEntity;
 
 import jakarta.persistence.Column;
 import jakarta.persistence.Entity;
@@ -19,11 +20,9 @@ public class SlurmApplicationDeploymentEntity {
     @GeneratedValue(strategy = GenerationType.UUID)
     private String deploymentId;
 
-    /*
-     * TODO: This should be a foreign key to a SlurmClusterEntity, but we don't have
-     * that yet.
-     */
-    private String slurmClusterId;
+    @ManyToOne
+    @JoinColumn(name = "cluster_id", foreignKey = @ForeignKey(name = "fk_dep_slurm_cluster"))
+    private SlurmClusterEntity slurmCluster;
 
     @ManyToOne
     @JoinColumn(name = "template_id", foreignKey = @ForeignKey(name = "fk_dep_app_template"))
@@ -90,12 +89,12 @@ public class SlurmApplicationDeploymentEntity {
         this.deploymentId = deploymentId;
     }
 
-    public String getSlurmClusterId() {
-        return slurmClusterId;
+    public SlurmClusterEntity getSlurmCluster() {
+        return slurmCluster;
     }
 
-    public void setSlurmClusterId(String slurmClusterId) {
-        this.slurmClusterId = slurmClusterId;
+    public void setSlurmCluster(SlurmClusterEntity slurmCluster) {
+        this.slurmCluster = slurmCluster;
     }
 
     public ApplicationTemplateEntity getApplicationTemplate() {
diff --git a/src/main/java/org/apache/airavata/application/service/SlurmApplicationDeploymentService.java b/src/main/java/org/apache/airavata/application/service/SlurmApplicationDeploymentService.java
index 5fb17fb8ad..02a6ed70de 100644
--- a/src/main/java/org/apache/airavata/application/service/SlurmApplicationDeploymentService.java
+++ b/src/main/java/org/apache/airavata/application/service/SlurmApplicationDeploymentService.java
@@ -8,6 +8,8 @@ import org.apache.airavata.application.model.deployment.SlurmApplicationDeployme
 import org.apache.airavata.application.model.template.ApplicationTemplateEntity;
 import org.apache.airavata.application.repository.ApplicationTemplateRepository;
 import org.apache.airavata.application.repository.SlurmApplicationDeploymentRepository;
+import org.apache.airavata.compute.model.SlurmClusterEntity;
+import org.apache.airavata.compute.repository.SlurmClusterRepository;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Service;
@@ -20,14 +22,17 @@ public class SlurmApplicationDeploymentService {
 
     private final SlurmApplicationDeploymentRepository deploymentRepository;
     private final ApplicationTemplateRepository templateRepository;
+    private final SlurmClusterRepository clusterRepository;
     private final SlurmApplicationDeploymentMapper mapper;
 
     public SlurmApplicationDeploymentService(
             SlurmApplicationDeploymentRepository deploymentRepository,
             ApplicationTemplateRepository templateRepository,
+            SlurmClusterRepository clusterRepository,
             SlurmApplicationDeploymentMapper mapper) {
         this.deploymentRepository = deploymentRepository;
         this.templateRepository = templateRepository;
+        this.clusterRepository = clusterRepository;
         this.mapper = mapper;
     }
 
@@ -53,6 +58,7 @@ public class SlurmApplicationDeploymentService {
     public SlurmApplicationDeploymentResponseDto createDeployment(SlurmApplicationDeploymentRequestDto request) {
         SlurmApplicationDeploymentEntity entity = mapper.toEntity(request);
         entity.setApplicationTemplate(resolveTemplate(request.getTemplateId()));
+        entity.setSlurmCluster(resolveCluster(request.getSlurmClusterId()));
         return mapper.toResponseDto(deploymentRepository.save(entity));
     }
 
@@ -63,6 +69,7 @@ public class SlurmApplicationDeploymentService {
         SlurmApplicationDeploymentEntity entity = findOrThrow(deploymentId);
         mapper.updateEntity(request, entity);
         entity.setApplicationTemplate(resolveTemplate(request.getTemplateId()));
+        entity.setSlurmCluster(resolveCluster(request.getSlurmClusterId()));
         return mapper.toResponseDto(deploymentRepository.save(entity));
     }
 
@@ -85,4 +92,17 @@ public class SlurmApplicationDeploymentService {
                 .orElseThrow(() ->
                         new ResponseStatusException(HttpStatus.NOT_FOUND, "Template not found: " + templateId));
     }
+
+    /**
+     * The cluster reference is optional — the column is nullable, so an absent id leaves
+     * the deployment unattached rather than failing. A supplied id must resolve.
+     */
+    private SlurmClusterEntity resolveCluster(String clusterId) {
+        if (clusterId == null || clusterId.isBlank()) {
+            return null;
+        }
+        return clusterRepository
+                .findById(clusterId)
+                .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Cluster not found: " + clusterId));
+    }
 }