def __init__(self, section, uuid, subfolder=os.curdir): """ Initializes the object by pointing it to a folder in the repository. Pass the uuid as a string. """ if section not in _valid_sections: retstr = ("Repository section '{}' not allowed. " "Valid sections are: {}".format( section, ",".join(_valid_sections))) raise ValueError(retstr) self._section = section self._uuid = uuid # If you want to change the sharding scheme, this is the only place # where changes should be needed FOR NODES AND WORKFLOWS # Of course, remember to migrate data! # We set a sharding of level 2+2 # Note that a similar sharding should probably has to be done # independently for calculations sent to remote computers in the # execmanager. # Note: I don't do any os.path.abspath (that internally calls # normpath, that may be slow): this is done abywat by the super # class. entity_dir = os.path.join( get_repository_folder('repository'), unicode(section), unicode(uuid)[:2], unicode(uuid)[2:4], unicode(uuid)[4:]) dest = os.path.join(entity_dir, unicode(subfolder)) # Internal variable of this class self._subfolder = subfolder # This will also do checks on the folder limits super(RepositoryFolder, self).__init__( abspath=dest, folder_limit=entity_dir)
def __init__(self): """ Initializes the object by creating a new temporary folder in the sandbox. """ # First check if the sandbox folder already exists sandbox = get_repository_folder('sandbox') if not os.path.exists(sandbox): os.makedirs(sandbox) abspath = tempfile.mkdtemp(dir=sandbox) super(SandboxFolder, self).__init__(abspath=abspath)
def get_node_repository_sub_folder(uuid): """Return the absolute path to the sub folder `path` within the repository of the node with the given UUID. :param uuid: UUID of the node :return: absolute path to node repository folder, i.e `/some/path/repository/node/12/ab/c123134-a123/path` """ from aiida.common.utils import get_repository_folder uuid = str(uuid) repo_dirpath = get_repository_folder('repository') node_dirpath = os.path.join(repo_dirpath, 'node', uuid[:2], uuid[2:4], uuid[4:], 'path') return node_dirpath
def __init__(self, sandbox_in_repo=True): """ Initializes the object by creating a new temporary folder in the sandbox. :param bool sandbox_in_repo: If True (default), creates the folder in the repository. If false, relies on the defaults of tempfile.mkdtemp """ # First check if the sandbox folder already exists if sandbox_in_repo: sandbox = get_repository_folder('sandbox') if not os.path.exists(sandbox): os.makedirs(sandbox) abspath = tempfile.mkdtemp(dir=sandbox) else: abspath = tempfile.mkdtemp() super(SandboxFolder, self).__init__(abspath=abspath)
def verdi_status(): """Print status of AiiDA services.""" # pylint: disable=broad-except,too-many-statements from aiida.cmdline.utils.daemon import get_daemon_status, delete_stale_pid_file from aiida.common.utils import Capturing, get_repository_folder from aiida.manage.external.rmq import get_rmq_url from aiida.manage.manager import get_manager exit_code = ExitCode.SUCCESS manager = get_manager() profile = manager.get_profile() # getting the profile try: profile = manager.get_profile() print_status(ServiceStatus.UP, 'profile', 'On profile {}'.format(profile.name)) except Exception as exc: print_status(ServiceStatus.ERROR, 'profile', 'Unable to read AiiDA profile') sys.exit(ExitCode.CRITICAL) # stop here - without a profile we cannot access anything # getting the repository repo_folder = 'undefined' try: repo_folder = get_repository_folder() except Exception as exc: print_status(ServiceStatus.ERROR, 'repository', 'Error with repo folder', exception=exc) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'repository', repo_folder) # Getting the postgres status by trying to get a database cursor database_data = [profile.database_username, profile.database_hostname, profile.database_port] try: with override_log_level(): # temporarily suppress noisy logging backend = manager.get_backend() backend.cursor() except Exception: print_status(ServiceStatus.DOWN, 'postgres', 'Unable to connect as {}@{}:{}'.format(*database_data)) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'postgres', 'Connected as {}@{}:{}'.format(*database_data)) # getting the rmq status try: with Capturing(capture_stderr=True): with override_log_level(): # temporarily suppress noisy logging comm = manager.create_communicator(with_orm=False) comm.stop() except Exception as exc: print_status(ServiceStatus.ERROR, 'rabbitmq', 'Unable to connect to rabbitmq', exception=exc) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'rabbitmq', 'Connected to {}'.format(get_rmq_url())) # getting the daemon status try: client = manager.get_daemon_client() delete_stale_pid_file(client) daemon_status = get_daemon_status(client) daemon_status = daemon_status.split('\n')[0] # take only the first line if client.is_daemon_running: print_status(ServiceStatus.UP, 'daemon', daemon_status) else: print_status(ServiceStatus.DOWN, 'daemon', daemon_status) exit_code = ExitCode.CRITICAL except Exception as exc: print_status(ServiceStatus.ERROR, 'daemon', 'Error getting daemon status', exception=exc) exit_code = ExitCode.CRITICAL # Note: click does not forward return values to the exit code, see https://github.com/pallets/click/issues/747 sys.exit(exit_code)