コード例 #1
0
ファイル: test_file_util.py プロジェクト: kfrancischen/pslx
 def test_get_cell_from_path(self):
     path = '/galaxy/aa-d/test'
     self.assertEqual('aa', FileUtil.get_cell_from_path(path))
     path = '/LOCAL/test'
     self.assertNotEqual('LOCAL', FileUtil.get_cell_from_path(path))
コード例 #2
0
ファイル: container_base.py プロジェクト: kfrancischen/pslx
    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