Browse Source

Log improvement

Change-Id: Ia7e0dee3820179c22fb8281c62d0a8241b72b718
changes/90/487690/1
Lingxian Kong 4 years ago
parent
commit
30c8e7dd60
  1. 13
      qinling/api/controllers/v1/execution.py
  2. 10
      qinling/api/controllers/v1/function.py
  3. 11
      qinling/api/controllers/v1/job.py
  4. 14
      qinling/api/controllers/v1/runtime.py
  5. 21
      qinling/engine/default_engine.py
  6. 9
      tools/vagrant/Vagrantfile
  7. 7
      tools/vagrant/qinling.conf.sample

13
qinling/api/controllers/v1/execution.py

@ -29,6 +29,7 @@ LOG = logging.getLogger(__name__)
class ExecutionsController(rest.RestController):
def __init__(self, *args, **kwargs):
self.engine_client = rpc.get_engine_client()
self.type = 'execution'
super(ExecutionsController, self).__init__(*args, **kwargs)
@ -38,9 +39,9 @@ class ExecutionsController(rest.RestController):
body=resources.Execution,
status_code=201
)
def post(self, execution):
params = execution.to_dict()
LOG.info("Creating execution. [params=%s]", params)
def post(self, body):
params = body.to_dict()
LOG.info("Creating %s. [params=%s]", self.type, params)
db_model = executions.create_execution(self.engine_client, params)
@ -49,7 +50,7 @@ class ExecutionsController(rest.RestController):
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.Executions)
def get_all(self):
LOG.info("Get all executions.")
LOG.info("Get all %ss.", self.type)
executions = [resources.Execution.from_dict(db_model.to_dict())
for db_model in db_api.get_executions()]
@ -59,7 +60,7 @@ class ExecutionsController(rest.RestController):
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.Execution, types.uuid)
def get(self, id):
LOG.info("Fetch execution [id=%s]", id)
LOG.info("Fetch resource.", resource={'type': self.type, 'id': id})
execution_db = db_api.get_execution(id)
@ -69,6 +70,6 @@ class ExecutionsController(rest.RestController):
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
def delete(self, id):
"""Delete the specified Execution."""
LOG.info("Delete execution [id=%s]", id)
LOG.info("Delete resource.", resource={'type': self.type, 'id': id})
return db_api.delete_execution(id)

10
qinling/api/controllers/v1/function.py

@ -46,13 +46,14 @@ class FunctionsController(rest.RestController):
def __init__(self, *args, **kwargs):
self.storage_provider = storage_base.load_storage_provider(CONF)
self.engine_client = rpc.get_engine_client()
self.type = 'function'
super(FunctionsController, self).__init__(*args, **kwargs)
@rest_utils.wrap_pecan_controller_exception
@pecan.expose()
def get(self, id):
LOG.info("Fetch function [id=%s]", id)
LOG.info("Fetch resource.", resource={'type': self.type, 'id': id})
download = strutils.bool_from_string(
pecan.request.GET.get('download', False)
@ -90,7 +91,7 @@ class FunctionsController(rest.RestController):
@rest_utils.wrap_pecan_controller_exception
@pecan.expose('json')
def post(self, **kwargs):
LOG.info("Creating function, params=%s", kwargs)
LOG.info("Creating %s, params: %s", self.type, kwargs)
# When using image to create function, runtime_id is not a required
# param.
@ -169,7 +170,7 @@ class FunctionsController(rest.RestController):
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
def delete(self, id):
"""Delete the specified function."""
LOG.info("Delete function [id=%s]", id)
LOG.info("Delete resource.", resource={'type': self.type, 'id': id})
with db_api.transaction():
func_db = db_api.get_function(id)
@ -200,7 +201,8 @@ class FunctionsController(rest.RestController):
if key in func.to_dict():
values.update({key: func.to_dict().get(key)})
LOG.info('Update function [id=%s, values=%s]' % (id, values))
LOG.info('Update resource, params: %s', values,
resource={'type': self.type, 'id': id})
with db_api.transaction():
func_db = db_api.update_function(id, values)

11
qinling/api/controllers/v1/job.py

@ -33,6 +33,8 @@ POST_REQUIRED = set(['function_id'])
class JobsController(rest.RestController):
type = 'job'
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(
resources.Job,
@ -48,7 +50,7 @@ class JobsController(rest.RestController):
)
first_time, next_time, count = jobs.validate_job(params)
LOG.info("Creating job. [job=%s]", params)
LOG.info("Creating %s, params: %s", self.type, params)
with db_api.transaction():
db_api.get_function(params['function_id'])
@ -79,14 +81,13 @@ class JobsController(rest.RestController):
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
def delete(self, id):
"""Delete job."""
LOG.info("Delete job [id=%s]" % id)
LOG.info("Delete resource.", resource={'type': self.type, 'id': id})
jobs.delete_job(id)
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.Job, types.uuid)
def get(self, id):
LOG.info("Fetch job [id=%s]", id)
LOG.info("Fetch resource.", resource={'type': self.type, 'id': id})
job_db = db_api.get_job(id)
return resources.Job.from_dict(job_db.to_dict())
@ -94,7 +95,7 @@ class JobsController(rest.RestController):
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.Jobs)
def get_all(self):
LOG.info("Get all jobs.")
LOG.info("Get all %ss.", self.type)
jobs = [resources.Job.from_dict(db_model.to_dict())
for db_model in db_api.get_jobs()]

14
qinling/api/controllers/v1/runtime.py

@ -33,13 +33,14 @@ UPDATE_ALLOWED = set(['name', 'description', 'image'])
class RuntimesController(rest.RestController):
def __init__(self, *args, **kwargs):
self.engine_client = rpc.get_engine_client()
self.type = 'runtime'
super(RuntimesController, self).__init__(*args, **kwargs)
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.Runtime, types.uuid)
def get(self, id):
LOG.info("Fetch runtime [id=%s]", id)
LOG.info("Fetch resource.", resource={'type': self.type, 'id': id})
runtime_db = db_api.get_runtime(id)
@ -48,7 +49,7 @@ class RuntimesController(rest.RestController):
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.Runtimes)
def get_all(self):
LOG.info("Get all runtimes.")
LOG.info("Get all %ss.", self.type)
runtimes = [resources.Runtime.from_dict(db_model.to_dict())
for db_model in db_api.get_runtimes()]
@ -69,7 +70,7 @@ class RuntimesController(rest.RestController):
'Required param is missing. Required: %s' % POST_REQUIRED
)
LOG.info("Creating runtime. [runtime=%s]", params)
LOG.info("Creating %s, params: %s", self.type, params)
params.update({'status': status.CREATING})
@ -81,9 +82,7 @@ class RuntimesController(rest.RestController):
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
def delete(self, id):
"""Delete runtime."""
LOG.info("Delete runtime [id=%s]", id)
LOG.info("Delete resource.", resource={'type': self.type, 'id': id})
with db_api.transaction():
runtime_db = db_api.get_runtime(id)
@ -117,7 +116,8 @@ class RuntimesController(rest.RestController):
if key in runtime.to_dict():
values.update({key: runtime.to_dict().get(key)})
LOG.info('Update runtime [id=%s, values=%s]' % (id, values))
LOG.info('Update resource, params: %s', values,
resource={'type': self.type, 'id': id})
with db_api.transaction():
if 'image' in values:

21
qinling/engine/default_engine.py

@ -27,7 +27,8 @@ class DefaultEngine(object):
self.orchestrator = orchestrator
def create_runtime(self, ctx, runtime_id):
LOG.info('Start to create runtime, id=%s', runtime_id)
LOG.info('Start to create.',
resource={'type': 'runtime', 'id': runtime_id})
with db_api.transaction():
runtime = db_api.get_runtime(runtime_id)
@ -49,16 +50,18 @@ class DefaultEngine(object):
runtime.status = status.ERROR
def delete_runtime(self, ctx, runtime_id):
LOG.info('Start to delete runtime, id=%s', runtime_id)
resource = {'type': 'runtime', 'id': runtime_id}
LOG.info('Start to delete.', resource=resource)
labels = {'runtime_id': runtime_id}
self.orchestrator.delete_pool(runtime_id, labels=labels)
db_api.delete_runtime(runtime_id)
LOG.info('Runtime %s deleted.', runtime_id)
LOG.info('Deleted.', resource=resource)
def update_runtime(self, ctx, runtime_id, image=None, pre_image=None):
LOG.info('Start to update runtime, id=%s, image=%s', runtime_id, image)
resource = {'type': 'runtime', 'id': runtime_id}
LOG.info('Start to update, image=%s', image, resource=resource)
labels = {'runtime_id': runtime_id}
ret = self.orchestrator.update_pool(
@ -69,12 +72,12 @@ class DefaultEngine(object):
values = {'status': status.AVAILABLE}
db_api.update_runtime(runtime_id, values)
LOG.info('Runtime %s updated.', runtime_id)
LOG.info('Updated.', resource=resource)
else:
values = {'status': status.AVAILABLE, 'image': pre_image}
db_api.update_runtime(runtime_id, values)
LOG.info('Runtime %s rollbacked.', runtime_id)
LOG.info('Rollbacked.', resource=resource)
def create_execution(self, ctx, execution_id, function_id, runtime_id,
input=None):
@ -148,8 +151,10 @@ class DefaultEngine(object):
db_api.create_function_service_mapping(mapping)
def delete_function(self, ctx, function_id):
LOG.info('Start to delete function, id=%s', function_id)
resource = {'type': 'function', 'id': function_id}
LOG.info('Start to delete.', resource=resource)
labels = {'function_id': function_id}
self.orchestrator.delete_function(function_id, labels=labels)
LOG.info('Deleted.', resource=resource)

9
tools/vagrant/Vagrantfile

@ -53,6 +53,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
git clone https://github.com/LingxianKong/qinling.git
cd qinling
sudo pip install -e .
cd ..
# Install python-qinlingclient
git clone https://github.com/LingxianKong/python-qinlingclient.git
cd python-qinlingclient
sudo pip install -e .
cd ..
# Initialize Qinling configuration.
sudo mkdir -p /vagrant/etc/qinling
@ -65,7 +72,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
qinling-db-manage --config-file /vagrant/etc/qinling/qinling.conf upgrade head
# Start Qinling service.
python qinling/cmd/launch.py --server api,engine --config-file /vagrant/etc/qinling/qinling.conf &
qinling-server --server api,engine --config-file /vagrant/etc/qinling/qinling.conf &
SHELL
end

7
tools/vagrant/qinling.conf.sample

@ -2,13 +2,16 @@
debug=True
verbose=False
log_file=/vagrant/log/qinling.log
logging_default_format_string=%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(instance)s%(message)s (%(name)s) [-]
logging_context_format_string=%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(instance)s%(message)s (%(name)s) [%(request_id)s %(user_identity)s]
logging_default_format_string=%(asctime)s %(process)d %(levelname)s %(message)s %(resource)s (%(name)s) [-]
logging_context_format_string=%(asctime)s %(process)d %(levelname)s %(message)s %(resource)s (%(name)s) [%(request_id)s %(user_identity)s]
logging_user_identity_format=%(user)s %(tenant)s
[api]
api_workers=1
[engine]
function_service_expiration = 86400
[database]
connection=mysql://root:password@localhost:3306/qinling

Loading…
Cancel
Save