Example #1
0
 def service_manage_report(self):
     admin_context = bilean_context.get_admin_context()
     try:
         db_api.service_update(admin_context, self.engine_id)
     except Exception as ex:
         LOG.error(_LE('Service %(id)s update failed: %(error)s'),
                   {'id': self.engine_id, 'error': six.text_type(ex)})
Example #2
0
    def __init__(self):
        super(ThreadGroupManager, self).__init__()
        self.workers = {}
        self.group = threadgroup.ThreadGroup()

        # Create dummy service task, because when there is nothing queued
        # on self.tg the process exits
        self.add_timer(cfg.CONF.periodic_interval, self._service_task)

        self.db_session = bilean_context.get_admin_context()
Example #3
0
 def _task(self, user_id, task_type):
     admin_context = bilean_context.get_admin_context()
     self.rpc_client.settle_account(
         admin_context, user_id, task=task_type)
     if task_type != self.DAILY:
         try:
             db_api.job_delete(
                 admin_context, self._generate_job_id(user_id, task_type))
         except exception.NotFound as e:
             LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e))
Example #4
0
 def __init__(self, **kwargs):
     super(BileanScheduler, self).__init__()
     self._scheduler = BackgroundScheduler()
     self.notifier = notifier.Notifier()
     self.engine_id = kwargs.get('engine_id', None)
     self.context = kwargs.get('context', None)
     if not self.context:
         self.context = bilean_context.get_admin_context()
     if cfg.CONF.bilean_task.store_ap_job:
         self._scheduler.add_jobstore(cfg.CONF.bilean_task.backend,
                                      url=cfg.CONF.bilean_task.connection)
Example #5
0
 def _init_service(self):
     admin_context = bilean_context.get_admin_context()
     srv = db_api.service_get_by_host_and_binary(admin_context,
                                                 self.host,
                                                 'bilean-engine')
     if srv is None:
         srv = db_api.service_create(admin_context,
                                     host=self.host,
                                     binary='bilean-engine',
                                     topic=self.topic)
     self.engine_id = srv.id
Example #6
0
 def delete_jobs(self, user):
     """Delete all jobs related the specific user."""
     admin_context = bilean_context.get_admin_context()
     for job_type in self.job_types:
         job_id = self._generate_job_id(user.id, job_type)
         try:
             if self._is_exist(job_id):
                 self._remove_job(job_id)
                 db_api.job_delete(admin_context, job_id)
         except Exception as e:
             LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e))
Example #7
0
 def _add_freeze_job(self, user):
     if user.rate == 0:
         return False
     total_seconds = float(user.balance / user.rate)
     run_date = timeutils.utcnow() + timedelta(seconds=total_seconds)
     job_params = {'run_date': run_date}
     job_id = self._generate_job_id(user.id, self.FREEZE)
     self._add_job(job_id, self.FREEZE, **job_params)
     # Save job to database
     job = {'id': job_id,
            'job_type': self.FREEZE,
            'scheduler_id': self.scheduler_id,
            'parameters': {'run_date': utils.format_time(run_date)}}
     admin_context = bilean_context.get_admin_context()
     db_api.job_create(admin_context, job)
     return True
Example #8
0
    def update_jobs(self, user):
        """Update user's billing job"""
        # Delete all jobs except daily job
        admin_context = bilean_context.get_admin_context()
        for job_type in self.NOTIFY, self.FREEZE:
            job_id = self._generate_job_id(user.id, job_type)
            try:
                if self._is_exist(job_id):
                    self._remove_job(job_id)
                    db_api.job_delete(admin_context, job_id)
            except Exception as e:
                LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e))

        if user.status == user.ACTIVE:
            self._add_notify_job(user)
        elif user.status == user.WARNING:
            self._add_freeze_job(user)
Example #9
0
 def _add_notify_job(self, user):
     if user.rate == 0:
         return False
     total_seconds = float(user.balance / user.rate)
     prior_notify_time = cfg.CONF.scheduler.prior_notify_time * 3600
     notify_seconds = total_seconds - prior_notify_time
     notify_seconds = notify_seconds if notify_seconds > 0 else 0
     run_date = timeutils.utcnow() + timedelta(seconds=notify_seconds)
     job_params = {'run_date': run_date}
     job_id = self._generate_job_id(user.id, self.NOTIFY)
     self._add_job(job_id, self.NOTIFY, **job_params)
     # Save job to database
     job = {'id': job_id,
            'job_type': self.NOTIFY,
            'scheduler_id': self.scheduler_id,
            'parameters': {'run_date': utils.format_time(run_date)}}
     admin_context = bilean_context.get_admin_context()
     db_api.job_create(admin_context, job)
Example #10
0
    def init_scheduler(self):
        """Init all jobs related to the engine from db."""
        admin_context = bilean_context.get_admin_context()
        jobs = [] or db_api.job_get_all(admin_context,
                                        scheduler_id=self.scheduler_id)
        for job in jobs:
            if self._is_exist(job.id):
                continue
            LOG.info(_LI("Add job '%(job_id)s' to scheduler '%(id)s'."),
                     {'job_id': job.id, 'id': self.scheduler_id})
            self._add_job(job.id, job.job_type, **job.parameters)

        LOG.info(_LI("Initialise users from keystone."))
        users = user_mod.User.init_users(admin_context)

        # Init daily job for all users
        if users:
            for user in users:
                job_id = self._generate_job_id(user.id, self.DAILY)
                if self._is_exist(job_id):
                    continue
                self._add_daily_job(user)
Example #11
0
 def __init__(self):
     self.resource_converter = converter.setup_resources()
     self.cnxt = context.get_admin_context()
     super(EventsNotificationEndpoint, self).__init__()
Example #12
0
 def __init__(self):
     self.resource_converter = converter.setup_resources()
     self.cnxt = context.get_admin_context()
     super(EventsNotificationEndpoint, self).__init__()