Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
A-Tune
提交
cff18d25
A
A-Tune
项目概览
openeuler
/
A-Tune
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
A-Tune
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
cff18d25
编写于
8月 29, 2020
作者:
W
willwolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
atune: refactor flask server code
上级
b9193edb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
125 addition
and
115 deletion
+125
-115
Makefile
Makefile
+7
-0
analysis/app.py
analysis/app.py
+51
-63
analysis/app_engine.py
analysis/app_engine.py
+18
-51
analysis/app_rest.py
analysis/app_rest.py
+48
-0
common/service/pyservice/pyservice.go
common/service/pyservice/pyservice.go
+1
-1
未找到文件。
Makefile
浏览文件 @
cff18d25
...
...
@@ -168,3 +168,10 @@ env:
@
echo
"export ATUNED_CLIENTKEY=
$(GRPC_CERT_PATH)
/client.key"
>>
$(CERT_PATH)
/env
@
echo
"export ATUNED_SERVERCN=server"
>>
$(CERT_PATH)
/env
@
echo
"END SET ENVIRONMENT VARIABLES"
startup
:
systemctl daemon-reload
systemctl restart atuned
systemctl restart atune-engine
run
:
all install startup
analysis/app.py
浏览文件 @
cff18d25
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) 20
19
Huawei Technologies Co., Ltd.
# Copyright (c) 20
20
Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
...
...
@@ -9,77 +9,65 @@
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Create: 20
19-10-29
# Create: 20
20-08-25
"""
A
pplication initialization, including log configuration, restful api registration.
Flask a
pplication initialization, including log configuration, restful api registration.
"""
import
os
import
ssl
import
sys
import
logging
from
configparser
import
ConfigParser
from
logging.handlers
import
SysLogHandler
from
flask
import
Flask
from
flask_restful
import
Api
sys
.
path
.
insert
(
0
,
os
.
path
.
dirname
(
__file__
)
+
"/../"
)
from
analysis.atuned
import
configurator
,
monitor
,
collector
,
profile
LOG
=
logging
.
getLogger
(
'werkzeug'
)
LOG
.
setLevel
(
logging
.
ERROR
)
APP
=
Flask
(
__name__
)
API
=
Api
(
APP
)
def
config_log
(
level
):
"""app config log"""
logging_format
=
logging
.
Formatter
(
'atuned: %(asctime)s [%(levelname)s] '
'%(name)s[line:%(lineno)d] : %(message)s'
)
syslog_handler
=
SysLogHandler
(
address
=
"/dev/log"
,
facility
=
SysLogHandler
.
LOG_LOCAL0
)
syslog_handler
.
setFormatter
(
logging_format
)
root_logger
=
logging
.
getLogger
()
root_logger
.
setLevel
(
level
)
root_logger
.
addHandler
(
syslog_handler
)
def
main
(
filename
):
"""app main function"""
if
not
os
.
path
.
exists
(
filename
):
return
config
=
ConfigParser
()
config
.
read
(
filename
)
level
=
logging
.
getLevelName
(
config
.
get
(
"log"
,
"level"
).
upper
())
config_log
(
level
)
APP
.
config
.
update
(
SESSION_COOKIE_SECURE
=
True
,
SESSION_COOKIE_HTTPONLY
=
True
,
SESSION_COOKIE_SAMESITE
=
'Lax'
)
API
.
add_resource
(
configurator
.
Configurator
,
'/v1/setting'
,
'/setting'
)
API
.
add_resource
(
monitor
.
Monitor
,
'/v1/monitor'
,
'/monitor'
)
API
.
add_resource
(
collector
.
Collector
,
'/v1/collector'
,
'/v1/collector'
)
API
.
add_resource
(
profile
.
Profile
,
'/v1/profile'
,
'/v1/profile'
)
if
config
.
has_option
(
"server"
,
"rest_tls"
)
and
config
.
get
(
"server"
,
"rest_tls"
)
==
"true"
:
cert_file
=
config
.
get
(
"server"
,
"tlsrestservercertfile"
)
key_file
=
config
.
get
(
"server"
,
"tlsrestserverkeyfile"
)
ca_file
=
config
.
get
(
"server"
,
"tlsrestcacertfile"
)
context
=
ssl
.
create_default_context
(
ssl
.
Purpose
.
CLIENT_AUTH
)
context
.
load_cert_chain
(
certfile
=
cert_file
,
keyfile
=
key_file
)
context
.
load_verify_locations
(
ca_file
)
context
.
verify_mode
=
ssl
.
CERT_REQUIRED
APP
.
run
(
host
=
config
.
get
(
"server"
,
"rest_host"
),
port
=
config
.
get
(
"server"
,
"rest_port"
),
ssl_context
=
context
)
else
:
APP
.
run
(
host
=
config
.
get
(
"server"
,
"rest_host"
),
port
=
config
.
get
(
"server"
,
"rest_port"
))
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
!=
2
:
sys
.
exit
(
-
1
)
main
(
sys
.
argv
[
1
])
class
App
:
"""flask application"""
def
__init__
(
self
):
self
.
app
=
Flask
(
__name__
)
self
.
app
.
config
.
update
(
SESSION_COOKIE_SECURE
=
True
,
SESSION_COOKIE_HTTPONLY
=
True
,
SESSION_COOKIE_SAMESITE
=
'Lax'
)
self
.
api
=
Api
(
self
.
app
)
@
staticmethod
def
config_log
(
level
):
"""app config log"""
log
=
logging
.
getLogger
(
'werkzeug'
)
log
.
setLevel
(
logging
.
ERROR
)
logging_format
=
logging
.
Formatter
(
'atuned: %(asctime)s [%(levelname)s] '
'%(module)s [%(pathname)s:%(lineno)d] : %(message)s'
)
syslog_handler
=
SysLogHandler
(
address
=
"/dev/log"
,
facility
=
SysLogHandler
.
LOG_LOCAL0
)
syslog_handler
.
setFormatter
(
logging_format
)
root_logger
=
logging
.
getLogger
()
root_logger
.
setLevel
(
level
)
root_logger
.
addHandler
(
syslog_handler
)
def
add_resource
(
self
):
"""flask app add resource"""
def
startup_app
(
self
,
filename
,
host_tag
,
port_tag
,
tls_tag
,
cert_tag
,
key_tag
,
ca_tag
):
"""start flask app"""
if
not
os
.
path
.
exists
(
filename
):
return
config
=
ConfigParser
()
config
.
read
(
filename
)
level
=
logging
.
getLevelName
(
config
.
get
(
"log"
,
"level"
).
upper
())
self
.
config_log
(
level
)
self
.
add_resource
()
host
=
config
.
get
(
"server"
,
host_tag
)
port
=
config
.
get
(
"server"
,
port_tag
)
context
=
None
if
config
.
has_option
(
"server"
,
tls_tag
)
and
config
.
get
(
"server"
,
tls_tag
)
==
"true"
:
cert_file
=
config
.
get
(
"server"
,
cert_tag
)
key_file
=
config
.
get
(
"server"
,
key_tag
)
ca_file
=
config
.
get
(
"server"
,
ca_tag
)
context
=
ssl
.
create_default_context
(
ssl
.
Purpose
.
CLIENT_AUTH
)
context
.
load_cert_chain
(
certfile
=
cert_file
,
keyfile
=
key_file
)
context
.
load_verify_locations
(
ca_file
)
context
.
verify_mode
=
ssl
.
CERT_REQUIRED
self
.
app
.
run
(
host
=
host
,
port
=
port
,
ssl_context
=
context
)
analysis/app_engine.py
浏览文件 @
cff18d25
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) 20
19
Huawei Technologies Co., Ltd.
# Copyright (c) 20
20
Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
...
...
@@ -12,70 +12,37 @@
# Create: 2020-07-17
"""
Engine application i
nitialization, including log configuration, restful api registr
ation.
Engine application i
mplement
ation.
"""
import
os
import
ssl
import
sys
import
logging
from
configparser
import
ConfigParser
from
logging
import
handlers
from
flask
import
Flask
from
flask_restful
import
Api
from
app
import
App
sys
.
path
.
insert
(
0
,
os
.
path
.
dirname
(
__file__
)
+
"/../"
)
from
analysis.engine
import
optimizer
,
classification
,
train
,
transfer
LOG
=
logging
.
getLogger
(
'werkzeug'
)
LOG
.
setLevel
(
logging
.
ERROR
)
APP
=
Flask
(
__name__
)
API
=
Api
(
APP
)
def
config_log
(
level
):
"""app config log"""
logging_format
=
logging
.
Formatter
(
'atuned: %(asctime)s [%(levelname)s] '
'%(name)s[line:%(lineno)d] : %(message)s'
)
syslog_handler
=
handlers
.
SysLogHandler
(
address
=
"/dev/log"
)
syslog_handler
.
setFormatter
(
logging_format
)
class
AppEngine
(
App
):
"""app engine"""
root_logger
=
logging
.
getLogger
()
root_logger
.
setLevel
(
level
)
root_logger
.
addHandler
(
syslog_handler
)
def
add_resource
(
self
):
"""flask app add resource"""
self
.
api
.
add_resource
(
optimizer
.
Optimizer
,
'/v1/optimizer'
,
'/v1/optimizer/<string:task_id>'
)
self
.
api
.
add_resource
(
classification
.
Classification
,
'/v1/classification'
,
'/v1/classification'
)
self
.
api
.
add_resource
(
train
.
Training
,
'/v1/training'
,
'/v1/training'
)
self
.
api
.
add_resource
(
transfer
.
Transfer
,
'/v1/transfer'
,
'/transfer'
)
def
main
(
filename
):
"""app main function"""
if
not
os
.
path
.
exists
(
filename
):
return
config
=
ConfigParser
()
config
.
read
(
filename
)
level
=
logging
.
getLevelName
(
config
.
get
(
"log"
,
"level"
).
upper
())
config_log
(
level
)
APP
.
config
.
update
(
SESSION_COOKIE_SECURE
=
True
,
SESSION_COOKIE_HTTPONLY
=
True
,
SESSION_COOKIE_SAMESITE
=
'Lax'
)
API
.
add_resource
(
optimizer
.
Optimizer
,
'/v1/optimizer'
,
'/v1/optimizer/<string:task_id>'
)
API
.
add_resource
(
classification
.
Classification
,
'/v1/classification'
,
'/v1/classification'
)
API
.
add_resource
(
train
.
Training
,
'/v1/training'
,
'/v1/training'
)
API
.
add_resource
(
transfer
.
Transfer
,
'/v1/transfer'
,
'/transfer'
)
if
config
.
has_option
(
"server"
,
"engine_tls"
)
and
config
.
get
(
"server"
,
"engine_tls"
)
==
"true"
:
cert_file
=
config
.
get
(
"server"
,
"tlsengineservercertfile"
)
key_file
=
config
.
get
(
"server"
,
"tlsengineserverkeyfile"
)
ca_file
=
config
.
get
(
"server"
,
"tlsenginecacertfile"
)
context
=
ssl
.
create_default_context
(
ssl
.
Purpose
.
CLIENT_AUTH
)
context
.
load_cert_chain
(
certfile
=
cert_file
,
keyfile
=
key_file
)
context
.
load_verify_locations
(
ca_file
)
context
.
verify_mode
=
ssl
.
CERT_REQUIRED
APP
.
run
(
host
=
config
.
get
(
"server"
,
"engine_host"
),
port
=
config
.
get
(
"server"
,
"engine_port"
),
ssl_context
=
context
)
else
:
APP
.
run
(
host
=
config
.
get
(
"server"
,
"engine_host"
),
port
=
config
.
get
(
"server"
,
"engine_port"
))
app_engine
=
AppEngine
()
app_engine
.
startup_app
(
filename
,
"engine_host"
,
"engine_port"
,
"engine_tls"
,
"tlsengineservercertfile"
,
"tlsengineserverkeyfile"
,
"tlsenginecacertfile"
)
if
__name__
==
'__main__'
:
...
...
analysis/app_rest.py
0 → 100644
浏览文件 @
cff18d25
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) 2019 Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Create: 2019-10-29
"""
Rest application implementation.
"""
import
os
import
sys
from
app
import
App
sys
.
path
.
insert
(
0
,
os
.
path
.
dirname
(
__file__
)
+
"/../"
)
from
analysis.atuned
import
configurator
,
monitor
,
collector
,
profile
class
AppRest
(
App
):
"""app rest"""
def
add_resource
(
self
):
"""flask app add resource"""
self
.
api
.
add_resource
(
configurator
.
Configurator
,
'/v1/setting'
,
'/setting'
)
self
.
api
.
add_resource
(
monitor
.
Monitor
,
'/v1/monitor'
,
'/monitor'
)
self
.
api
.
add_resource
(
collector
.
Collector
,
'/v1/collector'
,
'/v1/collector'
)
self
.
api
.
add_resource
(
profile
.
Profile
,
'/v1/profile'
,
'/v1/profile'
)
def
main
(
filename
):
"""app main function"""
app_engine
=
AppRest
()
app_engine
.
startup_app
(
filename
,
"rest_host"
,
"rest_port"
,
"rest_tls"
,
"tlsrestservercertfile"
,
"tlsrestserverkeyfile"
,
"tlsrestcacertfile"
)
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
!=
2
:
sys
.
exit
(
-
1
)
main
(
sys
.
argv
[
1
])
common/service/pyservice/pyservice.go
浏览文件 @
cff18d25
...
...
@@ -50,7 +50,7 @@ func (p *PyEngine) Set(cfg *config.Cfg) {
func
(
p
*
PyEngine
)
Run
()
error
{
cmdSlice
:=
make
([]
string
,
0
)
cmdSlice
=
append
(
cmdSlice
,
"python3"
)
cmdSlice
=
append
(
cmdSlice
,
path
.
Join
(
config
.
DefaultAnalysisPath
,
"app.py"
))
cmdSlice
=
append
(
cmdSlice
,
path
.
Join
(
config
.
DefaultAnalysisPath
,
"app
_rest
.py"
))
cmdSlice
=
append
(
cmdSlice
,
path
.
Join
(
config
.
DefaultConfPath
,
"atuned.cnf"
))
cmdStr
:=
strings
.
Join
(
cmdSlice
,
" "
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录