def instances(self, request, **kwargs): self.method_check(request, allowed=['get']) stats = [] app = self.get_app(kwargs) if not app: return HttpResponseNotFound(_("No such application")) if app.run_plan: for backend_conf in app.run_plan.backends: backend_data = { 'name': backend_conf.backend.name, 'ip': str(backend_conf.backend.ip), 'limits': { 'workers_min': backend_conf.workers_min, 'workers_max': backend_conf.workers_max, 'memory_per_worker': app.run_plan.memory_per_worker, 'memory_per_worker_bytes': app.run_plan.memory_per_worker * 1024 * 1024, 'backend_memory': app.run_plan.memory_per_worker * backend_conf.workers_max, 'backend_memory_bytes': app.run_plan.memory_per_worker * backend_conf.workers_max * 1024 * 1024, }} s = fetch_json_stats(str(backend_conf.backend.ip), backend_conf.stats) stats.append({'backend': backend_data, 'stats': s}) return self.create_response(request, stats)
def wait_until(self, application, running=True, timelimit=120): run_plan = self.backend.application_settings(application) if not run_plan: return False if running: action = _("start") else: action = _("stop") backend_conf = run_plan.backend_settings(self.backend) if backend_conf: ip = str(self.backend.ip) name = application.name # FIXME track pid change instead of initial sleep (?) sleep(3) timeout = datetime.now() + timedelta(seconds=timelimit) logged = False while datetime.now() <= timeout: s = fetch_json_stats(ip, backend_conf.stats) if running and s: return True if not running and not s: return True if logged: log.debug(_("Waiting for {name} to {action}").format( name=name, action=action)) else: log.info(_("Waiting for {name} to {action}").format( name=name, action=action)) logged = True sleep(2) else: log.error(_("Timeout reached for {name}").format(name=name)) return False
def test_uwsgi_stats_invalid(self): from upaas_admin.common.uwsgi import fetch_json_stats self.assertEqual(fetch_json_stats('127.0.0.1', 65000), None)