Exemplo n.º 1
0
    def convert_local_to_cell_path(cls, path, cell=''):
        if not path:
            return ''
        if cls.is_local_path(path) and EnvUtil.get_other_env_variable(
                var='GALAXY_fs_cell'):
            cell_name = cell if cell else EnvUtil.get_other_env_variable(
                var='GALAXY_fs_cell')
            path = path.replace('/LOCAL', '/galaxy/' + cell_name + '-d')

        return path
Exemplo n.º 2
0
 def get_cell_path_local_path(cls, path, cell=''):
     if cls.is_local_path(path) or '/galaxy/' not in path:
         return path
     try:
         this_cell = cell if cell else EnvUtil.get_other_env_variable(
             var='GALAXY_fs_cell')
         with open(
                 EnvUtil.get_other_env_variable('GALAXY_fs_global_config'),
                 'r') as infile:
             config = json.load(infile)
             root = config[this_cell]['fs_root']
             if root and root[-1] != '/':
                 root += '/'
             return root + '/'.join(path.split('/')[3:])
     except Exception as _:
         return ''
Exemplo n.º 3
0
 def get_cell_from_path(cls, path):
     if cls.is_local_path(path):
         return EnvUtil.get_other_env_variable(var='GALAXY_fs_cell')
     else:
         return path.replace('/galaxy/', '').split('-')[0]
Exemplo n.º 4
0
    def get_container_snapshot(self, send_backend=True):
        if not self._is_initialized:
            self._logger.error(
                "Warning: taking snapshot when the container [" +
                self.get_container_name() + "] is not initialized.")
            self._SYS_LOGGER.error(
                "Warning: taking snapshot when the container [" +
                self.get_container_name() + "] is not initialized.")

        snapshot = ContainerSnapshot()
        snapshot.container_name = self._container_name
        snapshot.is_initialized = self._is_initialized
        snapshot.status = self._status
        snapshot.class_name = self.get_full_class_name()
        snapshot.mode = self._mode
        snapshot.data_model = self.DATA_MODEL
        snapshot.log_file = FileUtil.convert_local_to_cell_path(
            glogging.get_logger_file(self._logger))
        snapshot.run_cell = EnvUtil.get_other_env_variable(
            var='GALAXY_fs_cell', fallback_value='')
        snapshot.snapshot_cell = FileUtil.get_cell_from_path(
            FileUtil.convert_local_to_cell_path(self._snapshot_file_folder))
        for key, val in self._counter.items():
            snapshot.counters[key] = val
        if self._start_time:
            snapshot.start_time = str(self._start_time)
        if self._end_time:
            snapshot.end_time = str(self._end_time)

        for op_name, op in self._node_name_to_node_dict.items():
            if 'Dummy' in op.get_class_name():
                continue
            op_output_file = FileUtil.join_paths_to_file(
                root_dir=FileUtil.join_paths_to_dir(
                    FileUtil.dir_name(self._snapshot_file_folder),
                    'operators'),
                base_name=op_name + '_SNAPSHOT_' +
                str(TimezoneUtil.cur_time_in_pst()) + '.pb')
            snapshot.operator_snapshot_map[op_name].CopyFrom(
                op.get_operator_snapshot(output_file=op_output_file))

        self._SYS_LOGGER.info(
            "Snapshot saved to folder [" +
            FileUtil.convert_local_to_cell_path(self._snapshot_file_folder) +
            '].')
        self._logger.info(
            "Snapshot saved to folder [" +
            FileUtil.convert_local_to_cell_path(self._snapshot_file_folder) +
            '].')
        output_file_name = FileUtil.join_paths_to_file(
            root_dir=FileUtil.join_paths_to_dir(
                FileUtil.dir_name(self._snapshot_file_folder), 'containers'),
            base_name=self._container_name + '_SNAPSHOT_' +
            str(TimezoneUtil.cur_time_in_pst()) + '.pb')

        FileUtil.write_proto_to_file(proto=snapshot,
                                     file_name=output_file_name)
        if self._backend and send_backend:
            try:
                self._backend.send_to_backend(snapshot=snapshot)
            except Exception as err:
                self._logger.error("Sending backend failed with error " +
                                   str(err) + '.')

        return snapshot