This commit is contained in:
Zihao Chen 2018-03-09 04:31:51 +00:00
Родитель be05473798
Коммит 3f0398e7a6
3 изменённых файлов: 123 добавлений и 13 удалений

105
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,105 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
.static_storage/
.media/
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/

15
logging_aux.py Normal file
Просмотреть файл

@ -0,0 +1,15 @@
import logging
def init_logger_aux(logger_name, filelog_name, console_level=logging.WARNING, file_level=logging.DEBUG):
logger = logging.getLogger(logger_name) # type: logging.Logger
logger.setLevel(file_level)
fh = logging.FileHandler(filelog_name)
fh.setLevel(file_level)
ch = logging.StreamHandler()
ch.setLevel(console_level)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)
return logger

Просмотреть файл

@ -2,6 +2,7 @@ import requests
import json
import logging
from collections import namedtuple
import logging_aux
GrowDecision = namedtuple("GrowDecision", "cores_to_grow nodes_to_grow sockets_to_grow")
IdleNode = namedtuple("IdleNode", "node_name idle_since")
@ -11,18 +12,7 @@ class AutoScaleRestClient(object):
self.hostname = hostname
self.grow_decision_api_route = "https://{}/HpcManager/api/auto-scale/grow-decision"
self.check_nodes_idle_route = "https://{}/HpcManager/api/auto-scale/check-nodes-idle"
self.logger = logging.getLogger("hpcframwork.restclient")
self.logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('hpcframwork.restclient.log')
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
self.logger.addHandler(fh)
self.logger.addHandler(ch)
self.logger = logging_aux.init_logger_aux("hpcframework.restclient", 'hpcframework.restclient.log')
def get_grow_decision(self):
url = self.grow_decision_api_route.format(self.hostname)
@ -40,7 +30,7 @@ class AutoScaleRestClient(object):
res = requests.post(url, data = nodes, headers = headers, verify = False)
if res.ok:
self.logger.info(res.content)
jobjs = json.loads(res.content)
jobjs = json.loads(res.content)
return [IdleNode(idle_info['NodeName'], idle_info['IdleSince']) for idle_info in jobjs]
else:
self.logger.error("status_code:{} content:{}".format(res.status_code, res.content))