Commit afcf2f9c authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Moved to hashmap for selecting computing managers and renamed SingleNode in Standalone.

parent aab0d1dd
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ class ComputingManager(object):
        return self._get_task_log(task, **kwargs)


class SingleNodeComputingManager(ComputingManager):
class StandaloneComputingManager(ComputingManager):
    pass


@@ -87,7 +87,7 @@ class SSHComputingManager(ComputingManager):



class InternalSingleNodeComputingManager(SingleNodeComputingManager):
class InternalStandaloneComputingManager(StandaloneComputingManager):
    
    def _start_task(self, task):

@@ -176,7 +176,7 @@ class InternalSingleNodeComputingManager(SingleNodeComputingManager):



class SSHSingleNodeComputingManager(SingleNodeComputingManager, SSHComputingManager):
class SSHStandaloneComputingManager(StandaloneComputingManager, SSHComputingManager):
    
    def _start_task(self, task, **kwargs):
        logger.debug('Starting a remote task "{}"'.format(self.computing))
@@ -189,7 +189,10 @@ class SSHSingleNodeComputingManager(SingleNodeComputingManager, SSHComputingMana
        webapp_conn_string = get_webapp_conn_string()
            
        # Handle container runtime
        if self.computing.default_container_runtime == 'singularity':
        container_runtime = task.computing_options.get('container_runtime', task.computing.default_container_runtime)

        # Runtime-specific part 
        if container_runtime == 'singularity':

            #if not task.container.supports_custom_interface_port:
            #     raise Exception('This task does not support dynamic port allocation and is therefore not supported using singularity on Slurm')
@@ -327,8 +330,11 @@ class SlurmSSHClusterComputingManager(ClusterComputingManager, SSHComputingManag
        # Set output and error files
        sbatch_args += ' --output=\$HOME/{}.log --error=\$HOME/{}.log '.format(task.uuid, task.uuid)

        # Submit the job
        if task.computing.default_container_runtime == 'singularity':
        # Handle container runtime
        container_runtime = task.computing_options.get('container_runtime', task.computing.default_container_runtime)

        # Runtime-specific part 
        if container_runtime == 'singularity':

            #if not task.container.supports_custom_interface_port:
            #     raise Exception('This task does not support dynamic port allocation and is therefore not supported using singularity on Slurm')
+9 −9
Original line number Diff line number Diff line
@@ -239,21 +239,21 @@ class Computing(models.Model):
    def manager(self):
        from . import computing_managers
        
        # Instantiate the computing manager based on type (if not already done)
        # Hash table mapping
        managers_mapping = {}
        managers_mapping['cluster'+'ssh+cli'+'user_keys'+'slurm'] = computing_managers.SlurmSSHClusterComputingManager
        managers_mapping['standalone'+'ssh+cli'+'user_keys'+'None'] = computing_managers.SSHStandaloneComputingManager
        managers_mapping['standalone'+'internal'+'internal'+'None'] = computing_managers.InternalStandaloneComputingManager
        
        # Instantiate the computing manager and return (if not already done)
        try:
            return self._manager
        except AttributeError:
            if self.type == 'cluster' and self.access_mode == 'ssh+cli' and self.auth_mode == 'user_keys' and self.wms == 'slurm':
                self._manager = computing_managers.SlurmSSHClusterComputingManager(self)
            elif self.type == 'standalone' and self.access_mode == 'ssh+cli' and self.auth_mode == 'user_keys' and self.wms is None:
                self._manager = computing_managers.SSHSingleNodeComputingManager(self)
            elif self.type == 'standalone' and self.access_mode == 'internal' and self.auth_mode == 'internal' and self.wms is None:
                self._manager = computing_managers.InternalSingleNodeComputingManager(self)
            else:
                raise ConsistencyException('Don\'t know how to instantiate a computing manager for computing resource of type "{}", access mode "{}" and WMS "{}"'.format(self.type, self.access_mode, self.wms))
            self._manager = managers_mapping[self.type+self.access_mode+self.auth_mode+str(self.wms)](self)
            return self._manager

    

#=========================
#  Tasks 
#=========================