mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Codestyle update (less use of #noqa)
This commit is contained in:
parent
66887f21b8
commit
ab5db4ae83
@ -25,13 +25,16 @@ def create_build_corpus_service(corpus):
|
||||
'name': 'build-corpus_{}'.format(corpus.id),
|
||||
'restart_policy': docker.types.RestartPolicy()
|
||||
}
|
||||
service_image = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/cqpserver:latest' # noqa
|
||||
service_image = \
|
||||
'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/cqpserver:latest'
|
||||
try:
|
||||
docker_client.services.create(service_image, **service_kwargs)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Create "{}" service raised '.format(service_kwargs['name']) # noqa
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Create "{}" service raised '.format(service_kwargs['name'])
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
else:
|
||||
corpus.status = 'queued'
|
||||
|
||||
@ -41,18 +44,24 @@ def checkout_build_corpus_service(corpus):
|
||||
try:
|
||||
service = docker_client.services.get(service_name)
|
||||
except docker.errors.NotFound:
|
||||
logging.error('Get "{}" service raised '.format(service_name)
|
||||
+ '[docker-NotFound] The service does not exist. '
|
||||
+ '(corpus.status: {} -> failed)'.format(corpus.status))
|
||||
logging.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.NotFound" The service does not exist. '
|
||||
+ '(corpus.status: {} -> failed)'.format(corpus.status)
|
||||
)
|
||||
corpus.status = 'failed'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Get "{}" service raised '.format(service_name)
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
except docker.errors.InvalidVersion:
|
||||
logging.error('Get "{}" service raised '.format(service_name)
|
||||
+ '[docker-InvalidVersion] One of the arguments is '
|
||||
+ 'not supported with the current API version.')
|
||||
logging.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.InvalidVersion" One of the arguments is '
|
||||
+ 'not supported with the current API version.'
|
||||
)
|
||||
else:
|
||||
service_tasks = service.tasks()
|
||||
if not service_tasks:
|
||||
@ -60,13 +69,16 @@ def checkout_build_corpus_service(corpus):
|
||||
task_state = service_tasks[0].get('Status').get('State')
|
||||
if corpus.status == 'queued' and task_state != 'pending':
|
||||
corpus.status = 'running'
|
||||
elif corpus.status == 'running' and task_state in ['complete', 'failed']: # noqa
|
||||
elif (corpus.status == 'running'
|
||||
and task_state in ['complete', 'failed']):
|
||||
try:
|
||||
service.remove()
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Remove "{}" service raised '.format(service_name) # noqa
|
||||
+ '[docker-APIError] The server returned an error. ' # noqa
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Remove "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
else:
|
||||
corpus.status = 'prepared' if task_state == 'complete' \
|
||||
@ -84,7 +96,8 @@ def create_cqpserver_container(corpus):
|
||||
'name': 'cqpserver_{}'.format(corpus.id),
|
||||
'network': 'nopaque_default'
|
||||
}
|
||||
container_image = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/cqpserver:latest' # noqa
|
||||
container_image = \
|
||||
'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/cqpserver:latest'
|
||||
# Check if a cqpserver container already exists. If this is the case,
|
||||
# remove it and create a new one
|
||||
try:
|
||||
@ -92,35 +105,45 @@ def create_cqpserver_container(corpus):
|
||||
except docker.errors.NotFound:
|
||||
pass
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Get "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Get "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
else:
|
||||
try:
|
||||
container.remove(force=True)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Remove "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Remove "{}" container raised '.format(container_kwargs['name']) # noqa
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
try:
|
||||
docker_client.containers.run(container_image, **container_kwargs)
|
||||
except docker.errors.ContainerError:
|
||||
# This case should not occur, because detach is True.
|
||||
logging.error('Run "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '[docker-ContainerError] The container exits with a '
|
||||
+ 'non-zero exit code and detach is False.')
|
||||
logging.error(
|
||||
'Run "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '"docker.errors.ContainerError" The container exits with a '
|
||||
+ 'non-zero exit code and detach is False.'
|
||||
)
|
||||
corpus.status = 'failed'
|
||||
except docker.errors.ImageNotFound:
|
||||
logging.error('Run "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '[docker-ImageNotFound] The specified image does not '
|
||||
+ 'exist.')
|
||||
logging.error(
|
||||
'Run "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '"docker.errors.ImageNotFound" The specified image does not '
|
||||
+ 'exist.'
|
||||
)
|
||||
corpus.status = 'failed'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Run "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Run "{}" container raised '.format(container_kwargs['name'])
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
else:
|
||||
corpus.status = 'analysing'
|
||||
|
||||
@ -132,16 +155,20 @@ def remove_cqpserver_container(corpus):
|
||||
except docker.errors.NotFound:
|
||||
pass
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Get "{}" container raised '.format(container_name)
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Get "{}" container raised '.format(container_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
else:
|
||||
try:
|
||||
container.remove(force=True)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Remove "{}" container raised '.format(container_name)
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Remove "{}" container raised '.format(container_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
corpus.status = 'prepared'
|
||||
|
@ -29,14 +29,16 @@ def create_job_service(job):
|
||||
mem_reservation=job.mem_mb * (10 ** 6)
|
||||
),
|
||||
'restart_policy': docker.types.RestartPolicy()}
|
||||
service_image = ('gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/'
|
||||
+ job.service + ':' + job.service_version)
|
||||
service_image = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/{}:{}'.format(
|
||||
job.service, job.service_version)
|
||||
try:
|
||||
docker_client.services.create(service_image, **service_kwargs)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Create "{}" service raised '.format(service_kwargs['name']) # noqa
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Create "{}" service raised '.format(service_kwargs['name'])
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
else:
|
||||
job.status = 'queued'
|
||||
@ -50,18 +52,22 @@ def checkout_job_service(job):
|
||||
service = docker_client.services.get(service_name)
|
||||
except docker.errors.NotFound:
|
||||
logging.error('Get "{}" service raised '.format(service_name)
|
||||
+ '[docker-NotFound] The service does not exist. '
|
||||
+ '"docker.errors.NotFound" The service does not exist. '
|
||||
+ '(job.status: {} -> failed)'.format(job.status))
|
||||
job.status = 'failed'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Get "{}" service raised '.format(service_name)
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
except docker.errors.InvalidVersion:
|
||||
logging.error('Get "{}" service raised '.format(service_name)
|
||||
+ '[docker-InvalidVersion] One of the arguments is '
|
||||
+ 'not supported with the current API version.')
|
||||
logging.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.InvalidVersion" One of the arguments is '
|
||||
+ 'not supported with the current API version.'
|
||||
)
|
||||
return
|
||||
else:
|
||||
service_tasks = service.tasks()
|
||||
@ -70,13 +76,15 @@ def checkout_job_service(job):
|
||||
task_state = service_tasks[0].get('Status').get('State')
|
||||
if job.status == 'queued' and task_state != 'pending':
|
||||
job.status = 'running'
|
||||
elif job.status == 'running' and task_state in ['complete', 'failed']: # noqa
|
||||
elif job.status == 'running' and task_state in ['complete', 'failed']:
|
||||
try:
|
||||
service.remove()
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Remove "{}" service raised '.format(service_name) # noqa
|
||||
+ '[docker-APIError] The server returned an error. ' # noqa
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Remove "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
else:
|
||||
if task_state == 'complete':
|
||||
@ -99,29 +107,37 @@ def remove_job_service(job):
|
||||
except docker.errors.NotFound:
|
||||
job.status = 'canceled'
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Get "{}" service raised '.format(service_name)
|
||||
+ '[docker-APIError] The server returned an error. '
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
except docker.errors.InvalidVersion:
|
||||
logging.error('Get "{}" service raised '.format(service_name)
|
||||
+ '[docker-InvalidVersion] One of the arguments is '
|
||||
+ 'not supported with the current API version.')
|
||||
logging.error(
|
||||
'Get "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.InvalidVersion" One of the arguments is '
|
||||
+ 'not supported with the current API version.'
|
||||
)
|
||||
return
|
||||
else:
|
||||
try:
|
||||
service.update(mounts=None)
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Update "{}" service raised '.format(service_name) # noqa
|
||||
+ '[docker-APIError] The server returned an error. ' # noqa
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Update "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
return
|
||||
try:
|
||||
service.remove()
|
||||
except docker.errors.APIError as e:
|
||||
logging.error('Remove "{}" service raised '.format(service_name) # noqa
|
||||
+ '[docker-APIError] The server returned an error. ' # noqa
|
||||
+ 'Details: {}'.format(e))
|
||||
logging.error(
|
||||
'Remove "{}" service raised '.format(service_name)
|
||||
+ '"docker.errors.APIError" The server returned an error. '
|
||||
+ 'Details: {}'.format(e)
|
||||
)
|
||||
|
||||
|
||||
def send_notification(job):
|
||||
|
Loading…
Reference in New Issue
Block a user