Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Progress tracking and scheduling #1

Open
wants to merge 103 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
db1073c
add base for the API and a scheduler test
anibalsolon Jul 11, 2020
0bef943
Merge branch 'develop' into feature/progress-tracking
anibalsolon Jul 12, 2020
964e06a
declutering setup.cfg, do not run test for helpers, add helper to path
anibalsolon Jul 12, 2020
6d2ec6a
add dummy test helper for scheduling, rename method, fix status/logs …
anibalsolon Jul 12, 2020
fae55e0
use uids instead of actual schedules for references
anibalsolon Jul 13, 2020
75edfe2
test for schedule results
anibalsolon Jul 13, 2020
9c0140b
allow delayed initialization
anibalsolon Jul 13, 2020
82969d3
Fixing inheritance ordering and move backend to the bottom
anibalsolon Jul 13, 2020
f1df845
initial test for Docker, using data_settings
anibalsolon Jul 13, 2020
e43a27e
data url parser
anibalsolon Jul 14, 2020
3fb3247
docker test for data settings & data config, start on monitoring serv…
anibalsolon Jul 14, 2020
7e5b805
Docker socket used for testing docker log messaging
anibalsolon Jul 21, 2020
05157c2
move scheduling to asyncio
anibalsolon Jul 21, 2020
557106d
docker async fetch logs
anibalsolon Jul 21, 2020
4ba7b72
merge log and docker run into one stream
anibalsolon Jul 21, 2020
93b0213
add conversor to data URI
anibalsolon Jul 23, 2020
b394ed6
Re-structure watchers
anibalsolon Jul 23, 2020
2ed0163
add some initial time and actually copy the data config
anibalsolon Jul 23, 2020
ec0fdc0
abstract runner as an status yielder, some refactoring on the reporte…
anibalsolon Jul 23, 2020
2056aad
add API and websocket to schedule stuff
anibalsolon Jul 23, 2020
c0f2394
fix log messages, add dependency
anibalsolon Jul 23, 2020
ec58800
Merge branch 'trunk' into feature/progress-tracking
anibalsolon Jul 23, 2020
97a9596
old, unused code
anibalsolon Jul 23, 2020
02f79cb
use yielded scheduler
anibalsolon Jul 23, 2020
7f861f2
reframe the keyerror as its own key error problem
anibalsolon Jul 23, 2020
59716a1
tag log message
anibalsolon Jul 23, 2020
e0d7dee
do not resend the schedule id, since it is already in the message
anibalsolon Jul 23, 2020
df29e0d
deal with s3 bids dir, and generate a data config for it
anibalsolon Jul 23, 2020
ae9a938
comment out unimplemented results
anibalsolon Jul 23, 2020
58956f7
add new req for app dir, start sql db, add semaphore to limit number …
anibalsolon Aug 4, 2020
67685e6
use failure tag, use RunStatus on tests, fix test logs access
anibalsolon Aug 8, 2020
cd80278
Merge branch 'primary' into feature/progress-tracking
anibalsolon Aug 15, 2020
4b39b0e
add singularity support, generalize code to containers, simulate erro…
anibalsolon Aug 18, 2020
bf890fb
ignore singularity images
anibalsolon Aug 18, 2020
8b86b4d
add default value when there is no folder i.e. data config used
anibalsolon Aug 18, 2020
6dac401
convert to image usage
anibalsolon Aug 18, 2020
9517b30
abstracting code to permute backends for testing
anibalsolon Aug 18, 2020
acd2a7c
add missing dependency
anibalsolon Aug 22, 2020
769a743
starting up with slurm
anibalsolon Aug 25, 2020
06c1886
slurm cluster for tests
anibalsolon Aug 25, 2020
7ad6269
removing unused requirements
anibalsolon Aug 25, 2020
324d96d
parametrize args
anibalsolon Aug 25, 2020
0d64677
guarantee queue is cancelled
anibalsolon Aug 29, 2020
6af8912
add schedule to messages, fix singularitu configs for networking
anibalsolon Aug 31, 2020
589009e
new endpoints to get results, status & metadata; allow participant sc…
anibalsolon Sep 10, 2020
d4e6d57
overwrite pre and post- will happen on the slurm side; add ret code
anibalsolon Sep 14, 2020
6ed4183
update dummy backend
anibalsolon Sep 14, 2020
4ed89aa
remove slurm old test
anibalsolon Sep 14, 2020
e55f8b7
test traverse deep objects
anibalsolon Sep 15, 2020
0a52fb0
add crash and log support
anibalsolon Sep 15, 2020
24416af
add unwatch to close sockets, handle not found schedules, await for t…
anibalsolon Sep 15, 2020
0eebde9
add result messages
anibalsolon Sep 15, 2020
f5aada5
unused args
anibalsolon Sep 15, 2020
ef7ecd6
show # of running tasks
anibalsolon Sep 15, 2020
665bce9
lint
anibalsolon Sep 15, 2020
bfe3789
spacious
anibalsolon Sep 15, 2020
f6fe76c
add original relative name to results
anibalsolon Sep 18, 2020
bbba016
allow log files
anibalsolon Sep 18, 2020
f96651d
parametrize backend on server response, add backend id for further mu…
anibalsolon Sep 19, 2020
ec8033d
better handling ws errors, making sure the tasks get cancelled
anibalsolon Sep 19, 2020
82fc59c
rework slurm testing, use current running cluster to perform tests
anibalsolon Sep 22, 2020
a7ca313
undo change on changelog
anibalsolon Sep 22, 2020
1f64e08
cleaning up old code
anibalsolon Sep 22, 2020
4b0a639
use the latest C-PAC image
anibalsolon Sep 22, 2020
48aa678
unused var
anibalsolon Sep 23, 2020
2c503db
not used
anibalsolon Sep 23, 2020
b4bf5fb
fix 3.6 errors
anibalsolon Sep 25, 2020
ae5372d
HAHA wat
anibalsolon Sep 25, 2020
67b4342
do not download the whole C-PAC
anibalsolon Sep 25, 2020
a05d612
add missing dependencies
anibalsolon Sep 25, 2020
e368654
upgrade dependency
anibalsolon Sep 29, 2020
95d237e
updates to set a default behavior when slurm_key and slurm_control ar…
Jan 12, 2021
3a3c622
added service file to start cpac-api on system start
Jan 12, 2021
64b7ffe
start script for creating a cpac cluster ami
Jan 12, 2021
909d55f
enh: tools for development
anibalsolon Apr 8, 2021
43c4d86
STASH
YiranCdr Apr 8, 2021
c58e848
Merge remote-tracking branch 'origin/feature/progress-tracking' into …
YiranCdr Apr 8, 2021
818276f
Feature: container params
YiranCdr Apr 8, 2021
076dd2c
Minor fix
YiranCdr Apr 8, 2021
b6cbfdd
Feature: authKey
YiranCdr Apr 13, 2021
d791b60
minor fix
YiranCdr Apr 13, 2021
2be08ae
enh: use real data to report node execution
anibalsolon Apr 23, 2021
4a82024
STASH - ALL POST
YiranCdr Apr 24, 2021
4fa25da
Merge remote-tracking branch 'origin/feature/ys-dev' into feature/ys-dev
YiranCdr Apr 24, 2021
3da61db
fix: add more logs, replace fixed image on template
anibalsolon May 4, 2021
4a5da25
fix: refactor auth
anibalsolon May 4, 2021
964f48f
fix: allow cors
anibalsolon May 4, 2021
8f2d1e0
fix: output folder for data config
anibalsolon May 4, 2021
76c435a
fix: match cpac new output
anibalsolon May 4, 2021
776800e
debounce
YiranCdr May 4, 2021
32fc778
Merge remote-tracking branch 'origin/feature/ys-dev' into feature/ys-dev
YiranCdr May 4, 2021
82b7e0a
debounce 1/2
YiranCdr May 4, 2021
3450eaa
auth token strip()
YiranCdr May 4, 2021
f8ccd29
post -> get
YiranCdr May 4, 2021
351a3a1
fix: add logs to slurm
anibalsolon May 4, 2021
b428b25
fix: exec date and exit
anibalsolon May 4, 2021
616143d
fix: more logs
anibalsolon May 4, 2021
60549b3
fix: run command in real shell
anibalsolon May 4, 2021
80a6ed0
Merge remote-tracking branch 'origin/feature/anibalsolon-dev' into fe…
YiranCdr May 5, 2021
370e378
Fix: pull-request fixes.
YiranCdr May 22, 2021
a2500d9
Merge branch 'feature/ys-dev' into feature/progress-tracking
YiranCdr May 22, 2021
2dc24ce
fix: method name
anibalsolon May 25, 2021
77a46a0
fix: method name
anibalsolon May 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
!.isort.cfg
!setup.cfg
*.orig
*.log
*.pot
__pycache__/*
.cache/*
.*.swp
*/.ipynb_checkpoints/*
.ipynb_checkpoints/*
*.sif

# Project files
.ropeproject
Expand All @@ -20,12 +20,16 @@ __pycache__/*
.settings
.idea
tags
.vscode

output

# Package files
*.egg
*.eggs/
.installed.cfg
*.egg-info
pip-wheel-metadata

# Unittest and coverage
htmlcov/*
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ install:
before_script:
- git config --global user.email "[email protected]"
- git config --global user.name "Travis"
- singularity pull shub://FCP-INDI/C-PAC || singularity pull docker://fcpindi/c-pac:latest
# - singularity pull shub://FCP-INDI/C-PAC || singularity pull docker://fcpindi/c-pac:latest
shnizzedy marked this conversation as resolved.
Show resolved Hide resolved
script:
- coverage run --append -m pytest
- coverage report -m
Expand Down
14 changes: 14 additions & 0 deletions cpac-api.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=API to allow CPAC Dashboard to communicate with CPAC CLI (e.g. for cluster)
After=sshd.service

[Service]
Type=simple
User=ubuntu
ExecStart=/home/ubuntu/miniconda3/bin/python -m cpac.api scheduler --backend slurm \
--singularity-image /shared/C-PAC.simg --slurm-host localhost:22 --slurm-username ubuntu
WorkingDirectory=/home/ubuntu

[Install]
Alias=cpac-api.service
WantedBy=mult-user.target
13 changes: 13 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[pytest]
log_cli = 1
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format=%Y-%m-%d %H:%M:%S
addopts = -s -v

testpaths = tests
norecursedirs =
dist
build
.tox
tests/helpers
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ coveralls
pytest
pytest-remotedata >= 0.3.2
pytest-runner
pytest-cov
pytest-runner
pytest-tornado
pytest-asyncio
sphinx
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ setuptools
spython >= 0.0.81
tabulate >= 0.8.6
tornado
websocket-client
appdirs == 1.4.4
23 changes: 5 additions & 18 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ install_requires =
pyyaml
tabulate >= 0.8.6
tornado
websocket-client
appdirs
dataclasses; python_version < "3.7"
shnizzedy marked this conversation as resolved.
Show resolved Hide resolved
python_requires = >=3.6

[options.packages.find]
Expand All @@ -58,28 +59,14 @@ testing =
imagesize
pytest
pytest-cov
pytest-runne
pytest-runner
pytest-tornado
pytest-asyncio
sphinx
[options.entry_points]
console_scripts =
cpac = cpac.__main__:run

[test]
addopts = --verbose -s
extras = True


[tool:pytest]
addopts = -s
# --cov cpac --cov-report term-missing -s
# -s
# --verbose
norecursedirs =
dist
build
.tox
testpaths = tests

[aliases]
build = bdist_wheel
release = build upload
Expand Down
18 changes: 0 additions & 18 deletions src/cpac/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@
clargs = {'group', 'utils'}


class ExtendAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
items = (getattr(namespace, self.dest) or []) + values
items = [x for n, x in enumerate(items) if x not in items[:n]]
setattr(namespace, self.dest, items)


def address(str): # pragma: no cover
addr, port = str.split(':')
port = int(port)
return addr, port


def parse_args(args):
cwd = os.getcwd()

Expand Down Expand Up @@ -142,8 +129,6 @@ def parse_args(args):
)

help_call = '--help' in sys.argv or '-h' in sys.argv
run_parser.register('action', 'extend', ExtendAction)
# run_parser.add_argument('--address', action='store', type=address)

if not help_call:
# These positional arguments are required unless we're just getting
Expand Down Expand Up @@ -173,21 +158,18 @@ def parse_args(args):
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
group_parser.register('action', 'extend', ExtendAction)

utils_parser = subparsers.add_parser(
'utils',
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
utils_parser.register('action', 'extend', ExtendAction)

crash_parser = subparsers.add_parser(
'crash',
add_help=True,
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
crash_parser.register('action', 'extend', ExtendAction)

crash_parser.add_argument(
'crashfile',
Expand Down
Empty file added src/cpac/api/__init__.py
Empty file.
128 changes: 128 additions & 0 deletions src/cpac/api/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import sys
import logging
import random
import string

from .. import __version__

_logger = logging.getLogger(__name__)


class ExtendAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
items = (getattr(namespace, self.dest) or []) + values
items = [x for n, x in enumerate(items) if x not in items[:n]]
setattr(namespace, self.dest, items)


def address(str):
addr, port = str.split(':')
port = int(port)
return addr, port


def parse_args(args):
parser = argparse.ArgumentParser(
description='cpac: a Python package that simplifies using C-PAC. CCs development version'
)

parser.add_argument(
'--version',
action='version',
version='cpac {ver}'.format(ver=__version__)
)

parser.add_argument(
'-v',
'--verbose',
dest="loglevel",
help="set loglevel to INFO",
action='store_const',
const=logging.INFO
)

parser.add_argument(
'-vv',
'--very-verbose',
dest="loglevel",
help="set loglevel to DEBUG",
action='store_const',
const=logging.DEBUG
)

subparsers = parser.add_subparsers(dest='command')

scheduler_parser = subparsers.add_parser('scheduler')
scheduler_parser.add_argument('--address', action='store', type=address, default='localhost:3333')
scheduler_parser.add_argument('--proxy', action='store_true')
scheduler_parser.add_argument('--backend', choices=['docker', 'singularity', 'slurm'], default='singularity')

scheduler_parser.add_argument('--singularity-image', nargs='?')

scheduler_parser.add_argument('--docker-image', nargs='?')

scheduler_parser.add_argument('--slurm-host', nargs='?')
scheduler_parser.add_argument('--slurm-username', nargs='?')
scheduler_parser.add_argument('--slurm-key', nargs='?')
scheduler_parser.add_argument('--slurm-control', nargs='?',
default=f'~/.ssh/{"".join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(24))}')
scheduler_parser.add_argument('--slurm-pip-install', nargs='?')
scheduler_parser.add_argument('--slurm-singularity-image', nargs='?')

parsed = parser.parse_args(args)

return parsed


def setup_logging(loglevel):
logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
logging.basicConfig(level=loglevel, stream=sys.stdout,
format=logformat, datefmt="%Y-%m-%d %H:%M:%S")


async def start(args):
from cpac.api.server import start
from cpac.api.backends import available_backends
from cpac.api.scheduling import Scheduler
from cpac.api.authKey import AuthKey

print("Running server")
print("Auth key: ", AuthKey.generate_key())

backend = args.backend
cmd_args = vars(args)

backend = available_backends[backend](
id=backend,
**{
arg.split('_', 1)[1]: val
for arg, val in cmd_args.items()
if arg.startswith(backend)
}
)

async with Scheduler(backend, proxy=args.proxy) as scheduler:
await start(args.address, scheduler)
await scheduler


def main(args):
command = args[0]
args = parse_args(args[1:])
setup_logging(args.loglevel)

if args.command == 'scheduler':
import asyncio
asyncio.run(start(args))


def run():
main(sys.argv)


if __name__ == "__main__":
run()
15 changes: 15 additions & 0 deletions src/cpac/api/authKey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import uuid


class AuthKey:
key = None

@staticmethod
def generate_key():
if not AuthKey.key:
AuthKey.key = str(uuid.uuid1())
return AuthKey.key

@staticmethod
def get_key():
return AuthKey.key
9 changes: 9 additions & 0 deletions src/cpac/api/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .docker import DockerBackend
from .singularity import SingularityBackend
from .slurm import SLURMBackend

available_backends = {
'docker': DockerBackend,
'singularity': SingularityBackend,
'slurm': SLURMBackend,
}
Loading