-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from sara-nl/SPD-417
SPD-417: add scanner and get resources from tokens
- Loading branch information
Showing
12 changed files
with
251 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
python local_example.py --design_doc $DOC --view $VIEW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import logging | ||
import sys | ||
|
||
import picasconfig | ||
from picas.picaslogger import picaslogger | ||
from picas.clients import CouchDB | ||
from picas.executers import execute | ||
from picas.util import arg_parser | ||
|
||
picaslogger.propagate = False | ||
|
||
# expand the parser for the example | ||
parser = arg_parser() | ||
parser.add_argument("--cores", default=1, type=str, help="Number of cores for the job") | ||
parser.set_defaults(design_doc="SingleCore") | ||
args = parser.parse_args() | ||
|
||
client = CouchDB(url=picasconfig.PICAS_HOST_URL, db=picasconfig.PICAS_DATABASE, username=picasconfig.PICAS_USERNAME, password=picasconfig.PICAS_PASSWORD) | ||
|
||
work_avail = client.is_view_nonempty(args.view, design_doc=args.design_doc) | ||
if work_avail: | ||
picaslogger.info(f"Starting a picas clients checking view {args.view} in design document {args.design_doc}") | ||
command = ["sbatch", f"--cpus-per-task={args.cores}", f"--export=VIEW={args.view},DOC={args.design_doc}", "N-core-job.sh"] | ||
execute(command) | ||
else: | ||
picaslogger.info(f"Not starting a picas client, there is nothing to do in view {args.view} and for the designdocs {args.design_doc}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
''' | ||
@helpdesk: SURF helpdesk <helpdesk@surf.nl> | ||
usage: python pushTokens.py | ||
description: | ||
Connects to PiCaS server | ||
Creates three tokens, two for single-core, one for multi-core | ||
Loads the tokens | ||
''' | ||
|
||
import sys | ||
import os | ||
import couchdb | ||
import random | ||
import picasconfig | ||
|
||
def getNextIndex(): | ||
db = get_db() | ||
|
||
index = 0 | ||
while db.get(f"token_{index}") is not None: | ||
index+=1 | ||
|
||
return index | ||
|
||
def loadTokens(db, ncores=1): | ||
i = getNextIndex() | ||
|
||
token = { | ||
'_id': 'token_' + str(i), | ||
'type': 'token', | ||
'lock': 0, | ||
'done': 0, | ||
'hostname': '', | ||
'scrub_count': 0, | ||
'input': 'echo $SLURM_CPUS_PER_TASK', | ||
'exit_code': '', | ||
'cores': f'{ncores}' | ||
} | ||
db.update([token]) | ||
|
||
def get_db(): | ||
server = couchdb.Server(picasconfig.PICAS_HOST_URL) | ||
username = picasconfig.PICAS_USERNAME | ||
pwd = picasconfig.PICAS_PASSWORD | ||
server.resource.credentials = (username,pwd) | ||
db = server[picasconfig.PICAS_DATABASE] | ||
return db | ||
|
||
if __name__ == '__main__': | ||
#Create a connection to the server | ||
db = get_db() | ||
#Load the tokens to the database | ||
loadTokens(db, ncores=1) | ||
loadTokens(db, ncores=1) | ||
loadTokens(db, ncores=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.