Commit 37d85c18 authored by Alexandre Boyer's avatar Alexandre Boyer
Browse files

Add resource monitoring

parent 1231567c
......@@ -4,8 +4,8 @@
*.egg-info
## CLI gitignore config
# Commands history
diva_evaluation_cli/bin/private_src/implementation/status/command_history.json
# Monitor logs
*_monitoring.json
# Virtual environments
python_env/
......@@ -6,9 +6,10 @@ stages:
build:
stage: build
image: python:3.5-slim
image: python:3.5-stretch
script:
- python3 -m pip install -r ./requirements.txt
- python3 -m pip install -e .
- actev -h
- actev validate-system
1.1.1 - 11.20.18
================
* Add a new feature: resource monitoring
* Add some comments in the entry points
* bug fixes
1.1 - 11.16.18
==============
......@@ -21,7 +28,7 @@
* Add a new argument to pre/post/process-chunk: --system-cache-dir
1.0.1 - 10.24.18
==============
================
* Add a new argument to reset-chunk: --system-cache-dir
* Modify names of the arguments composed of multiple words. Example: --chunk_id becomes --chunk-id
......
__version__ = '1.1'
__version__ = '1.1.1'
"""
USAGE
ActEV
Description
-----------
Run any common stub command.
"""Main CLI module
Args
----
system-setup
design-chunks
experiment-init
process-chunk
experiment-cleanup
merge-chunks
Gather every actev command modules to parse and execute code in order to
test a system.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
......@@ -59,6 +47,7 @@ ActevExperimentCleanup(),
def cli_parser():
""" Main command to parse commands and arguments
"""
# Initialize logger
logging.getLogger().setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter('[%(asctime)s] diva_evaluation_cli-%(levelname)s: %(message)s'))
......@@ -86,4 +75,4 @@ def main():
cli_parser()
if __name__ == '__main__':
main()
main()
"""Actev module
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
import abc
import logging
import sys
from diva_evaluation_cli.bin.private_src.implementation.resources_monitoring.monitor import Monitor
from diva_evaluation_cli.bin.private_src.implementation.status.status_factory import StatusFactory
class ActevCommand():
""" Abstract class that represents an actev command.
Every actev modules must inherit from this class and
implement the following methods
Attributes:
command (str): Name of the actev command
entry_point (function): Python function that represents an entry point
before_entry_point (function, optional): Python function that should be executed before entry_point method
after_entry_point (function, optional): Python function that should be executed after entry_point method
"""
__metaclass__ = abc.ABCMeta
def __init__(self, command, entry_point, before_entry_point=None, after_entry_point=None):
"""
@param command: string representing the name of the command
"""
Args:
command (str): Name of the actev command
entry_point (function): Python function that represents an entry point
before_entry_point (function, optional): Python function that should be executed before entry_point method
after_entry_point (function, optional): Python function that should be executed after entry_point method
"""
self.command = command
self.entry_point = entry_point
......@@ -22,18 +45,28 @@ class ActevCommand():
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
@param arg_parser: python arg parser to describe how to parse the command
"""
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
"""
return
def before_command(self, args):
""" Execute an action before executing the command
Args:
args (:obj:`dict`): contains the arguments passed during the actev command call
"""
if self.before_entry_point:
self.before_entry_point(**args.__dict__)
def after_command(self, args):
""" Execute an action after executing the command
Args:
args (:obj:`dict`): contains the arguments passed during the actev command call
"""
if self.after_entry_point:
self.after_entry_point(**args.__dict__)
......@@ -41,7 +74,9 @@ class ActevCommand():
def command(self, args):
""" Gets arguments and passe them to an entry point. Catch the exception occured.
@param args: list of arguments passed during the command call
Args:
args (:obj:`dict`): contains the arguments passed during the actev command call
"""
del args.__dict__['object']
del args.__dict__['func']
......@@ -51,13 +86,14 @@ class ActevCommand():
StatusFactory.generateStatus(self, 'start', args.__dict__)
self.before_command(args)
self.entry_point(**args.__dict__)
mon = Monitor(self.entry_point, args, self.command)
mon.run_monitor()
self.after_command(args)
logging.info("%s done" % self.command)
StatusFactory.generateStatus(self, 'done', args.__dict__)
except:
logging.exception("Issue during %s" % self.command)
logging.error("Issue during %s" % self.command)
StatusFactory.generateStatus(self, 'issue', args.__dict__)
sys.exit(1)
"""
USAGE
ActEV design-chunks
Description
-----------
Given a file index and an activity index, produce a chunks file that is suitable for the system.
"""Actev module: design-chunks
Args
----
file-index or f: path to file index json file for test set
activity-index or a: path to activity index json file for test set
output or o: path to save chunks file
nb_video-per-chunk or n: number of videos in the chunk
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
from diva_evaluation_cli.src.entry_points.actev_design_chunks import entry_point
class ActevDesignChunks(ActevCommand):
"""Given a file index and an activity index, produce a chunks file that is suitable for the system.
Command args:
* file-index or f: path to file index json file for test set
* activity-index or a: path to activity index json file for test set
* output or o: path to save chunks file
* nb_video-per-chunk or n: number of videos in the chunk
"""
def __init__(self):
super(ActevDesignChunks, self).__init__('design-chunks', entry_point)
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description = "Produce a chunks file that is suitable for the system"
required_named = arg_parser.add_argument_group('required named arguments')
......
"""
USAGE
ActEV exec
Description
-----------
Calls a team-implemented API. Captures time stamps, resource usage, etc.
Args
----
file-index or f: path to file index json file for test set
activity-index or a: path to activity index json file for test set
chunks or c: path to chunks json file
nb-video-per-chunk or n: number of videos in the chunk
video-location or v: path to videos content
system-cache-dir or s: path to system cache directory
config-file or C: path to config file
output-file: path to merge chunks command result
chunk_result: path to chunks json file after merge chunks execution
"""Actev module: exec
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
import logging
......@@ -26,14 +12,29 @@ from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
from diva_evaluation_cli.bin.private_src.entry_points.actev_exec import entry_point
class ActevExec(ActevCommand):
"""Calls a team-implemented API. Captures time stamps, resource usage, etc.
Command args:
* file-index or f: path to file index json file for test set
* activity-index or a: path to activity index json file for test set
* chunks or c: path to chunks json file
* nb-video-per-chunk or n: number of videos in the chunk
* video-location or v: path to videos content
* system-cache-dir or s: path to system cache directory
* config-file or C: path to config file
* output-file: path to merge chunks command result
* chunk_result: path to chunks json file after merge chunks execution
"""
def __init__(self):
super(ActevExec, self).__init__('exec', entry_point)
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Calls a team-implemented API. Captures time stamps, resource usage, etc."
required_named = arg_parser.add_argument_group('required named arguments')
......@@ -42,11 +43,11 @@ class ActevExec(ActevCommand):
required_named.add_argument("-a", "--activity-index", help="path to activity index json file", required=True)
required_named.add_argument("-c", "--chunks", help="path to chunks json file", required=True)
arg_parser.add_argument("-n", "--nb-videos-per-chunk", help="number of videos in a chunk")
required_named.add_argument("-v", "--video-location", help="path to videos content", required=True)
required_named.add_argument("-s", "--system-cache-dir", help="path to system cache directory", required=True)
arg_parser.add_argument("-C", "--config-file", help="path to config file")
required_named.add_argument("-o", "--output-file", help="path to merge chunks command result", required=True)
required_named.add_argument("-r", "--chunks-result", help="path to chunks json file after merge chunks execution", required=True)
arg_parser.set_defaults(func=ActevExec.command, object=self)
......
"""
USAGE
"""Actev module: experiment-cleanup
ActEV experiment-cleanup
Description
-----------
Close any servers, terminates cluster (future functionality), etc.
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
import logging
......@@ -15,14 +13,18 @@ from diva_evaluation_cli.src.entry_points.actev_experiment_cleanup import entry_
class ActevExperimentCleanup(ActevCommand):
"""Close any servers, terminates cluster (future functionality), etc.
"""
def __init__(self):
super(ActevExperimentCleanup, self).__init__('experiment-cleanup', entry_point)
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description = "Close any servers, terminates cluster, etc."
arg_parser.set_defaults(func=ActevExperimentCleanup.command, object=self)
"""
USAGE
ActEV experiment-init
Description
-----------
Start servers, starts cluster, etc.
Args
----
file-index or f: path to file index json file for test set
activity-index or a: path to activity index json file for test set
chunks or c: path to chunks json file
video-location or v: path to videos content
system-cache-dir or s: path to system cache directory
config-file or C: path to config file
"""Actev module: experiment-init
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
import logging
......@@ -24,14 +13,26 @@ from diva_evaluation_cli.bin.private_src.entry_points.actev_experiment_init impo
from diva_evaluation_cli.src.entry_points.actev_experiment_init import entry_point
class ActevExperimentInit(ActevCommand):
"""Start servers, starts cluster, etc.
Command args:
* file-index or f: path to file index json file for test set
* activity-index or a: path to activity index json file for test set
* chunks or c: path to chunks json file
* video-location or v: path to videos content
* system-cache-dir or s: path to system cache directory
* config-file or C: path to config file
"""
def __init__(self):
super(ActevExperimentInit, self).__init__('experiment-init', entry_point, before_entry_point=before_entry_point)
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Start servers, starts cluster, etc."
required_named = arg_parser.add_argument_group('required named arguments')
......
"""
USAGE
ActEV get-system
Description
-----------
Downloads a credentialed, web-accessible content into src
"""Actev module: get-system
Args
----
url or u: url to get the system
location or l: path to store the system
user or U: username to access the url
password or p: password to access the url
token or t: token to access the url
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
import logging
......@@ -23,14 +13,25 @@ from diva_evaluation_cli.bin.private_src.entry_points.actev_get_system import en
from diva_evaluation_cli.bin.private_src.implementation.get_system.system_types_definition import system_types
class ActevGetSystem(ActevCommand):
"""Downloads a credentialed, web-accessible content into src
Command args:
* url or u: url to get the system
* location or l: path to store the system
* user or U: username to access the url
* password or p: password to access the url
* token or t: token to access the url
"""
def __init__(self):
super(ActevGetSystem, self).__init__('get-system', entry_point)
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Downloads a credentialed, web-accessible content into src"
......
"""
USAGE
"""Actev module: get-system docker
ActEV get-system docker
Description
-----------
Downloads a docker image
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Args
----
user or U: url to get the system
password or p: password to access the url
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified.
"""
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
class ActevGetSystemDocker(ActevCommand):
"""Downloads a docker image
Command args:
* user or U: url to get the system
* password or p: password to access the url
"""
def __init__(self):
super(ActevGetSystemDocker, self).__init__('docker', "get_docker.sh")
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Downloads a docker image"
required_named = arg_parser.add_argument_group('required named arguments')
......
"""
USAGE
ActEV get-system git
Description
-----------
Clones a git repository
Args
----
location or l: path to store the system
user or U: url to get the system
password or p: password to access the url
token or t: token to access the url
install-cli or i: install the cli to use it
Warning: this file should not be modified.
"""
"""Actev module: get-system git
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Warning: this file should not be modified: see src/entry_points to add your source code.
"""
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
class ActevGetSystemGit(ActevCommand):
"""Clones a git repository
Command Args:
* location or l: path to store the system
* user or U: url to get the system
* password or p: password to access the url
* token or t: token to access the url
* install-cli or i: install the cli to use it
"""
def __init__(self):
super(ActevGetSystemGit, self).__init__('git', "get_git.sh")
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Downloads a git repository"
required_named = arg_parser.add_argument_group('required named arguments')
......
"""
USAGE
"""Actev module: get-system other
ActEV get-system other
Description
-----------
Downloads a web resources as a tar file
Actev modules are used to parse actev commands in order to get arguments
before calling associated entry point methods to execute systems.
Args
----
location or l: path to store the system
user or U: url to get the system
password or p: password to access the url
token or t: token to access the url
Warning: this file should not be modified: see src/entry_points to add your source code.
Warning: this file should not be modified.
"""
from diva_evaluation_cli.bin.commands.actev_command import ActevCommand
class ActevGetSystemOther(ActevCommand):
"""Downloads a web resources as a tar file
Command args:
* location or l: path to store the system
* user or U: url to get the system
* password or p: password to access the url
* token or t: token to access the url
"""
def __init__(self):
super(ActevGetSystemOther, self).__init__('other', "get_other.sh")
def cli_parser(self, arg_parser):
""" Configure the description and the arguments (positional and optional) to parse.
"""Configure the description and the arguments (positional and optional) to parse.
Args:
arg_parser(:obj:`ArgParser`): Python arg parser to describe how to parse the command
@param arg_parser: python arg parser to describe how to parse the command
"""
arg_parser.description= "Downloads a web resources as a tar file"
required_named = arg_parser.add_argument_group('required named arguments')
......